eslint
This commit is contained in:
parent
55f631de02
commit
3c5bf74581
11
index.js
11
index.js
@ -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);
|
||||||
};
|
};
|
||||||
|
10
test/main.js
10
test/main.js
@ -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-/'
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user