complete documentation for subdir option

This commit is contained in:
Timo Hocker 2019-12-11 12:47:42 +01:00
parent 81283fd3c5
commit b2d9e9f0bf
2 changed files with 13 additions and 2 deletions

View File

@ -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/
```

View File

@ -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)) {