From b2d9e9f0bf9b7452587e91acd9b3f55f4b13f5b9 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Wed, 11 Dec 2019 12:47:42 +0100 Subject: [PATCH] complete documentation for subdir option --- README.md | 14 ++++++++++++-- index.js | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index af5091a..c94bc0d 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ app.listen(3000); api/get-root.js ```js -// will respont to get requests on / +// will respond to get requests on / module.exports = (req, res, next, opts) => { res.send(opts.foo); }; @@ -53,8 +53,18 @@ module.exports = (req, res, next, opts) => { api/post-subfolder.js ```js -// will respont to post requests on /subfolder/ +// will respond to post requests on /subfolder/ module.exports = (req, res, next, opts) => { res.send(opts.foo); }; ``` + +optionally, you can set a subdirectory for all requests + +```js +//... + +requestor(app, 'api', {foo: 'bar'}, 'subdir'); + +// requests that before responded to /foo/bar/ will now respond to /subdir/foo/bar/ +``` diff --git a/index.js b/index.js index ced4d6e..7cddfca 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ const path = require('path'); * @param {any} app express app * @param {string} modulefolder * @param {any} opts object to pass to the handlers (for example database access) + * @param {string} subdir subdirectory for all requests (app will respond to /subdir/... instead of /...) */ module.exports = function (app, modulefolder, opts = {}, subdir = '') { for (const f of fs.readdirSync(modulefolder)) {