Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple middleware per route #17

Open
kylejreed opened this issue Oct 22, 2022 · 1 comment
Open

Multiple middleware per route #17

kylejreed opened this issue Oct 22, 2022 · 1 comment

Comments

@kylejreed
Copy link
Contributor

For some APIs, its nice to have the ability to run some pre/post operations on a per-route or per-group basis. For example, you want some public routes, and some protected routes requiring a JWT token. Maybe this can currently be achieved in the Bao.before(), but the DX around it could be improved.

One solution is to allow things like Bao.get() to accept multiple IHandler's.

get(...handlers: IHandler[]) {}

Another step up from that would be to implement a multi-router support like Express or Koa does

const app = new Bao();
const HelloRouter = new Router('/hello');
HelloRouter.before(logger());
HelloRouter.get(protect(), ctx => ctx.sendText('world'));

app.use(HelloRouter); // or app.use('/hello', HelloRouter) if preferred DX
@cngo-github
Copy link

Both things would be helpful. I miss Express's modular approach to route handlers, being able to define middlewares per route, and being able to use multiple middleware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants