This commit is contained in:
Timo Hocker 2019-12-11 09:38:35 +01:00
parent 55f631de02
commit 3c5bf74581
2 changed files with 17 additions and 4 deletions

View File

@ -11,9 +11,16 @@ module.exports = function (app, modulefolder, opts) {
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.replace(/^root/i, '').replace(/\./g, '/').replace(/\/+/g, '/'); url =
'/' +
url
.replace(/^root/i, '')
.replace(/\./g, '/')
.replace(/\/+/g, '/');
const handler = require(('./' + modulefolder + '/' + f).replace(/\/\.\//g, '/').replace(/\/+/g, '/')); const handler = require(('./' + modulefolder + '/' + f)
.replace(/\/\.\//g, '/')
.replace(/\/+/g, '/'));
const func = (req, res, next) => { const func = (req, res, next) => {
handler(req, res, next, opts); handler(req, res, next, opts);
}; };

View File

@ -1,4 +1,4 @@
const {describe, it} = require('mocha'); const { describe, it } = require('mocha');
const expect = require('chai').expect; const expect = require('chai').expect;
const requestor = require('../index'); const requestor = require('../index');
@ -25,6 +25,12 @@ const mock = {
describe('requestor', () => { describe('requestor', () => {
it('should detect all requests on root', () => { it('should detect all requests on root', () => {
requestor(mock, './test/onroot', {}); requestor(mock, './test/onroot', {});
expect(mock.registered).to.have.all.keys(['post-/', 'get-/', 'put-/', 'delete-/', 'all-/']); expect(mock.registered).to.have.all.keys([
'post-/',
'get-/',
'put-/',
'delete-/',
'all-/'
]);
}); });
}); });