kakengloh/bagel

Cannot use before middlewares with router

Opened this issue · 0 comments

I was trying to add cors to my project and noticed the before middlewares don't seem to execute. I created a test middleware to run before and that doesn't seem to execute either.

import { Bagel, Router } from '@kakengloh/bagel';

const app = new Bagel();
const router = new Router();
router.get('', async (req, res, next) => {
  res.send('success');
})
app.use(async (req, res, next) => {
  console.log('successfully ran middleware');
  next();
});
app.mount('/test', router);

app.listen(3001);
;

I think this is because I am using a router. When I swap out the router for app.get('test', async (req, res, next)=>{ res.send('success' }) then the middleware logger executes.
I think it has to do with these lines: https://github.com/kakengloh/bagel/blob/main/src/bagel.ts#L32-L34
Since it only appends the middlewares to existing routers. And I don't see the already existing middlewares being added to a new router when it is added.