| 607 | } |
| 608 | |
| 609 | @Module({ |
| 610 | controllers: [DataController], |
| 611 | }) |
| 612 | class DataModule implements NestModule { |
| 613 | configure(consumer: MiddlewareConsumer) { |
| 614 | consumer |
| 615 | .apply((req, res, next) => { |
| 616 | req.extras = { data: class="st">'Data attached in middleware' }; |
| 617 | req.headers[class="st">'ping'] = class="st">'pong'; |
| 618 | |
| 619 | class="cm">// When global prefix is set and the route is the root path |
| 620 | if (req.originalUrl === class="st">'/api') { |
| 621 | return res.end(JSON.stringify({ success: true, pong: class="st">'pong' })); |
| 622 | } |
| 623 | next(); |
| 624 | }) |
| 625 | .forRoutes(class="st">'{*path}'); |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | beforeEach(async () => { |
| 630 | app = ( |