fix(fastify-adapter): global prefix exclusion path handling w/middleware

This commit is contained in:
Kyle Lilly
2025-04-02 10:37:31 -04:00
parent 05d8ac796b
commit c91eeff7bb
2 changed files with 38 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ import {
Module,
NestMiddleware,
NestModule,
Param,
Query,
Req,
RequestMethod,
@@ -439,6 +440,11 @@ describe('Middleware (FastifyAdapter)', () => {
async rootPath(@Req() req: FastifyRequest['raw']) {
return { success: true, root: true };
}
@Get(':id')
async record(@Req() req: FastifyRequest['raw'], @Param('id') id: string) {
return { success: true, record: id };
}
}
@Module({
@@ -535,6 +541,32 @@ describe('Middleware (FastifyAdapter)', () => {
.expect(200, { success: true, root: true });
});
it(`GET forRoutes('{*path}') with global prefix and exclude pattern with wildcard`, async () => {
app.setGlobalPrefix('/api', { exclude: ['/{*path}'] });
await app.init();
await app.getHttpAdapter().getInstance().ready();
await request(app.getHttpServer())
.get('/pong')
.expect(200, { success: true, pong: 'pong' });
await request(app.getHttpServer())
.get('/api/abc123')
.expect(200, { success: true, pong: 'abc123' });
});
it(`GET forRoutes('{*path}') with global prefix and exclude pattern with parameter`, async () => {
app.setGlobalPrefix('/api', { exclude: ['/:id'] });
await app.init();
await app.getHttpAdapter().getInstance().ready();
await request(app.getHttpServer())
.get('/abc123')
.expect(200, { success: true, record: 'abc123' });
await request(app.getHttpServer())
.get('/api/pong')
.expect(200, { success: true, pong: 'pong' });
});
it(`GET forRoutes('{*path}') with global prefix and global prefix options`, async () => {
app.setGlobalPrefix('/api', { exclude: ['/'] });
await app.init();