diff --git a/packages/cli/src/routeGeneration/templates/express.hbs b/packages/cli/src/routeGeneration/templates/express.hbs index 73f7b7d36..3f4ec0428 100644 --- a/packages/cli/src/routeGeneration/templates/express.hbs +++ b/packages/cli/src/routeGeneration/templates/express.hbs @@ -111,6 +111,7 @@ export function RegisterRoutes(app: Router) { validatedArgs, successStatus: {{successStatus}}, }); + next(); } catch (err) { return next(err); } diff --git a/tests/fixtures/express/server.ts b/tests/fixtures/express/server.ts index 1cb1b9310..4b386eb76 100644 --- a/tests/fixtures/express/server.ts +++ b/tests/fixtures/express/server.ts @@ -36,7 +36,21 @@ app.use((req: any, res: any, next: any) => { req.stringValue = 'fancyStringForContext'; next(); }); +let postRouteMiddlwareCalled = false; RegisterRoutes(app); +app.get('/reset-post-route-middleware-status', (req, res, next) => { + postRouteMiddlwareCalled = false; + res.json({ postRouteMiddlwareCalled }).send(); + next(); +}); +app.get('/post-route-middleware-status', (req, res, next) => { + res.json({ postRouteMiddlwareCalled }).send(); + next(); +}); +app.use((req, res, next) => { + postRouteMiddlwareCalled = true; + next(); +}); // It's important that this come after the main routes are registered app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => { diff --git a/tests/integration/express-server.spec.ts b/tests/integration/express-server.spec.ts index d3bb88272..befbee715 100644 --- a/tests/integration/express-server.spec.ts +++ b/tests/integration/express-server.spec.ts @@ -24,13 +24,22 @@ import { const basePath = '/v1'; describe('Express Server', () => { + it('can reset the post route middleware status', () => { + return verifyGetRequest('/reset-post-route-middleware-status', (_err, res) => { + expect(res.body.postRouteMiddlwareCalled).to.eq(false); + }); + }); it('can handle get request to root controller`s path', () => { return verifyGetRequest(basePath + '/', (_err, res) => { const model = res.body as TestModel; expect(model.id).to.equal(1); }); }); - + it('can verify that post request middleware was called', () => { + return verifyGetRequest('/post-route-middleware-status', (_err, res) => { + expect(res.body.postRouteMiddlwareCalled).to.eq(true); + }); + }); it('can handle get request to root controller`s method path', () => { return verifyGetRequest(basePath + '/rootControllerMethodWithPath', (_err, res) => { const model = res.body as TestModel;