add subdirectory option
This commit is contained in:
parent
d53641ea1b
commit
d680bf4c5e
4
index.js
4
index.js
@ -8,11 +8,11 @@ const path = require('path');
|
|||||||
* @param {string} modulefolder
|
* @param {string} modulefolder
|
||||||
* @param {any} opts object to pass to the handlers (for example database access)
|
* @param {any} opts object to pass to the handlers (for example database access)
|
||||||
*/
|
*/
|
||||||
module.exports = function (app, modulefolder, opts) {
|
module.exports = function (app, modulefolder, opts = {}, subdir = '') {
|
||||||
for (const f of fs.readdirSync(modulefolder)) {
|
for (const f of fs.readdirSync(modulefolder)) {
|
||||||
const regex = /(.*?)-(.*?)\.js/;
|
const regex = /(.*?)-(.*?)\.js/;
|
||||||
let [, method, url] = regex.exec(f);
|
let [, method, url] = regex.exec(f);
|
||||||
url = '/' + url + '/';
|
url = '/' + subdir + '/' + url + '/';
|
||||||
url = url
|
url = url
|
||||||
.replace(/^\/root/i, '/')
|
.replace(/^\/root/i, '/')
|
||||||
.replace(/\./g, '/')
|
.replace(/\./g, '/')
|
||||||
|
Reference in New Issue
Block a user