diff --git a/README.md b/README.md index cd590ca..a597441 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ npx directory-serve /path-to-file | username | undefined | Client auth username | `npx directory-serve /path-of-directory --username=my_username ` | | password | undefined | Client auth password (optional) | `npx directory-serve /path-of-directory --username=my_username --password=my_password ` | | delete | false | To delete file/folder | `npx directory-serve /path-of-directory --delete=true` | +| debug | false | Debug mode | `npx directory-serve /path-of-directory --delete=true --debug=true` | ## Examples @@ -91,11 +92,11 @@ npm i ```bash npm run dev /path-of-directory ``` + ## For Contributing [Contribution Guide](/docs/CONTRIBUTING.MD) - ## Screenshot ### CLI diff --git a/bin/index.js b/bin/index.js index 096a5cd..25fbba2 100644 --- a/bin/index.js +++ b/bin/index.js @@ -23,6 +23,8 @@ Options --password ..... Client auth password --delete ..... Delete file/folder + +--debug ..... Debug mode * To serve a directory directory-serve /path-of-directory @@ -35,25 +37,47 @@ directory-serve /path-of-file const options = yargs .usage(yargsMessage) .option('p', { - default: 8989, alias: 'port', describe: 'Change default port', type: 'integer', demandOption: false, + default: 8989, + alias: 'port', + describe: 'Change default port', + type: 'integer', + demandOption: false, }) .option('u', { - default: true, alias: 'uploadFile', describe: 'File upload mode', type: 'boolean', + default: true, + alias: 'uploadFile', + describe: 'File upload mode', + type: 'boolean', }) .options('username', { - default: undefined, describe: 'Client auth username', type: 'string', demandOption: false, + default: undefined, + describe: 'Client auth username', + type: 'string', + demandOption: false, }) .options('password', { - default: undefined, describe: 'Client auth password', type: 'string', demandOption: false, + default: undefined, + describe: 'Client auth password', + type: 'string', + demandOption: false, }) .options('delete', { - default: false, alias: 'deleteFile', describe: 'Delete file/folder', type: 'boolean', demandOption: false, + default: false, + alias: 'deleteFile', + describe: 'Delete file/folder', + type: 'boolean', + demandOption: false, + }) + .options('debug', { + default: false, + describe: 'Debug mode', + type: 'boolean', + demandOption: false, }) - .help(true) - .argv; + .help(true).argv; const { - uploadFile, username, password, deleteFile, + uploadFile, username, password, deleteFile, debug, } = options; let path = options._[0]; if (!path) { @@ -85,7 +109,8 @@ if (isFile) { * Auth */ app.use((req, res, next) => authMiddleware(req, res, next, { - username, password, + username, + password, })); /** * SERVER @@ -94,6 +119,7 @@ app.use((req, res) => handler(req, res, { path, uploadFile, deleteFile, + debug, })); app.listen(options.port, () => { diff --git a/lib/helper/html.js b/lib/helper/html.js index b573723..d9f7915 100644 --- a/lib/helper/html.js +++ b/lib/helper/html.js @@ -1,13 +1,23 @@ -// const fs = require('fs-extra'); +const fs = require('fs-extra'); -// const cssLoader = () => fs.readFileSync('lib/helper/style.css', 'utf8'); -const createHtmlResponse = (body) => '\n' +const cssLoader = (debug) => { + try { + return ``; + } catch (error) { + if (debug) { + console.log('Failed to load stylesheet'); + console.log(error); + } + } + return ''; +}; +const createHtmlResponse = (body, { debug = false } = {}) => '\n' + '\n' - + '
\n' - + '' + + `\n${ + // + '' // + '' - // + `` - + `