add swagger ui
This commit is contained in:
parent
9c42fb00fc
commit
9701f7101e
@ -50,7 +50,7 @@ EXPOSE 3000
|
||||
|
||||
# Healthcheck
|
||||
#HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
|
||||
# CMD node -e "require('http').get('http://localhost:3000/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
|
||||
# CMD node -e "require('http').get('http://localhost:3000/api/v1/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
|
||||
|
||||
# Démarrer l'application avec dumb-init
|
||||
ENTRYPOINT ["dumb-init", "--"]
|
||||
|
||||
37
src/main.ts
37
src/main.ts
@ -3,6 +3,7 @@ import { AppModule } from './app.module';
|
||||
import { ValidationPipe, Logger } from '@nestjs/common';
|
||||
import helmet from 'helmet';
|
||||
import { KeycloakExceptionFilter } from './filters/keycloak-exception.filter';
|
||||
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
@ -13,11 +14,47 @@ async function bootstrap() {
|
||||
app.useGlobalFilters(new KeycloakExceptionFilter());
|
||||
app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
|
||||
app.setGlobalPrefix('api/v1');
|
||||
|
||||
// Swagger Configuration
|
||||
const config = new DocumentBuilder()
|
||||
.setTitle('DCB User Service API')
|
||||
.setDescription('API de gestion des utilisateurs pour le système DCB')
|
||||
.setVersion('1.0')
|
||||
.addTag('users', 'Gestion des utilisateurs')
|
||||
.addBearerAuth(
|
||||
{
|
||||
type: 'http',
|
||||
scheme: 'bearer',
|
||||
bearerFormat: 'JWT',
|
||||
name: 'JWT',
|
||||
description: 'Entrez votre token JWT',
|
||||
in: 'header',
|
||||
},
|
||||
'JWT-auth', // Nom de la référence
|
||||
)
|
||||
.addServer('http://localhost:3000', 'Développement local')
|
||||
.addServer('https://api.example.com', 'Production')
|
||||
.build();
|
||||
const document = SwaggerModule.createDocument(app, config);
|
||||
SwaggerModule.setup('api/docs', app, document, {
|
||||
customSiteTitle: 'DCB User Service API Docs',
|
||||
customfavIcon: 'https://nestjs.com/img/logo_text.svg',
|
||||
customJs: [
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui-bundle.min.js',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui-standalone-preset.min.js',
|
||||
],
|
||||
customCssUrl: [
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui.min.css',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui-standalone-preset.min.css',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui.css',
|
||||
],
|
||||
});
|
||||
app.enableCors({ origin: '*' })
|
||||
|
||||
const port = process.env.PORT || 3000;
|
||||
await app.listen(port);
|
||||
|
||||
logger.log(`Application running on http://localhost:${port}`);
|
||||
logger.log(`Swagger documentation available at http://localhost:${port}/api/docs`);
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user