Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function isGen(v) {
try {
if (regeneratorRuntime) {
/* global regeneratorRuntime */
return regeneratorRuntime.isGeneratorFunction(v);
}
} catch(e) {
return isGeneratorFunction(v);
}
}
use(...args) {
args = flatten(args);
const result = [];
for (let i = 0; i < args.length; i++) {
let cb = args[i];
if (typeof cb !== 'function') {
throw new Error(
'middleware must be a function ' +
'but got ' + typeof cb
);
}
// runtime convert generator function to ...
if (isGeneratorFunction(cb)) {
cb = convert(cb);
}
result.push(cb);
}
this.middlewares.push.apply(this.middlewares, result);
return this;
}
reg(path,fn,opts={}){
if(!path)
throw Error('path must be existed')
if(!fn)
throw Error('callback must be a function')
if(isGeneratorFunction(fn)){
fn = convert(fn)
}
opts = opts || {}
let r = {
regexp : pathToRegexp(path),
fn : fn,
prefix:this.opts.prefix||'/'
}
this.m.push(r)
return this
}
use(fn){
if (typeof fn !== 'function') throw new TypeError('middleware must be a function!');
if(isGeneratorFunction(fn)){
fn = convert(fn)
}
this.middlewares.push(fn)
return this
}
callback(){