Utilisation d'un préfixe global

This commit is contained in:
Emmy D'Anello 2024-12-15 20:46:53 +01:00
parent 1fbd8ee5c3
commit 0a3fe8c243
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
2 changed files with 3 additions and 1 deletions

View File

@ -1,2 +1,3 @@
DATABASE_URL="postgres://username:password@localhost:5432/traintrape-moi"
JWT_SECRET="CHANGE_ME"
API_GLOBAL_PREFIX="api"

View File

@ -6,6 +6,7 @@ import { ClassSerializerInterceptor, ValidationPipe } from '@nestjs/common'
async function bootstrap() {
const app = await NestFactory.create(AppModule, { cors: true })
app.setGlobalPrefix(process.env.API_GLOBAL_PREFIX ?? '')
app.useGlobalPipes(new ValidationPipe({ transform: true }))
app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)))
@ -17,7 +18,7 @@ async function bootstrap() {
.build()
const document = SwaggerModule.createDocument(app, config)
SwaggerModule.setup('', app, document)
SwaggerModule.setup(process.env.API_GLOBAL_PREFIX ?? '', app, document)
await app.listen(process.env.PORT ?? 3000)
}
bootstrap()