@stacksjs/router
Version:
The Stacks framework router.
24 lines (23 loc) • 481 B
JavaScript
export class Middleware {
name;
priority;
handle;
constructor(config) {
this.name = config.name;
this.priority = config.priority ?? 10;
this.handle = config.handle;
}
toRouterHandler() {
const handle = this.handle.bind(this);
return async (req, next) => {
try {
await handle(req);
} catch (thrown) {
if (thrown instanceof Response)
return thrown;
throw thrown;
}
return next();
};
}
}