add subdirectory option

This commit is contained in:
Timo Hocker 2019-12-11 12:17:29 +01:00
parent d53641ea1b
commit d680bf4c5e

View File

@ -8,11 +8,11 @@ const path = require('path');
* @param {string} modulefolder
* @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)) {
const regex = /(.*?)-(.*?)\.js/;
let [, method, url] = regex.exec(f);
url = '/' + url + '/';
url = '/' + subdir + '/' + url + '/';
url = url
.replace(/^\/root/i, '/')
.replace(/\./g, '/')