Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return async ctx => {
// By default, we get an instance of the controller from the context
// using `controllers.` as the key
let inst = await ctx.get(`controllers.${controllerCtor.name}`, {
optional: true,
});
if (inst === undefined) {
inst = await instantiateClass(controllerCtor, ctx);
}
return inst;
};
}
async function sayHello(ctx: Context) {
const greeter = await instantiateClass(Greeter, ctx);
console.log(greeter.hello());
}
request: Request,
) {
if (typeof customParser === 'string') {
const parser = this.parsers.find(
p =>
p.name === customParser ||
p.name === builtinParsers.mapping[customParser],
);
if (parser) {
debug('Using custom parser %s', customParser);
return parser.parse(request);
}
} else if (typeof customParser === 'function') {
if (isBodyParserClass(customParser)) {
debug('Using custom parser class %s', customParser.name);
const parser = await instantiateClass(
customParser as Constructor,
this.ctx!,
);
return parser.parse(request);
} else {
debug('Using custom parser function %s', customParser.name);
return customParser(request);
}
}
throw new Error('Custom parser not found: ' + customParser);
}
}