complete documentation for subdir option
This commit is contained in:
parent
81283fd3c5
commit
b2d9e9f0bf
14
README.md
14
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/
|
||||
```
|
||||
|
1
index.js
1
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)) {
|
||||
|
Reference in New Issue
Block a user