mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-27 09:04:54 +00:00
feat:mvp1 initial commit
This commit is contained in:
37
src/main.ts
Normal file
37
src/main.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
import { Logger } from 'nestjs-pino';
|
||||
import { AppModule } from './app.module';
|
||||
const DEFAULT_PORT = 3000;
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
|
||||
app.useLogger(app.get(Logger));
|
||||
const config = app.get(ConfigService);
|
||||
const swaggerDocument = await createSwagger(app);
|
||||
|
||||
if (config.getOrThrow<string>('NODE_ENV') === 'dev') {
|
||||
SwaggerModule.setup(config.getOrThrow<string>('SWAGGER_API_DOCS_PATH'), app, swaggerDocument, {
|
||||
swaggerOptions: {
|
||||
tagsSorter: 'alpha',
|
||||
docExpansion: 'none',
|
||||
},
|
||||
});
|
||||
}
|
||||
await app.listen(process.env.PORT ?? DEFAULT_PORT);
|
||||
}
|
||||
|
||||
function createSwagger(app: INestApplication) {
|
||||
const swaggerConfig = new DocumentBuilder()
|
||||
.setTitle('Zod APIs')
|
||||
.setDescription('API documentation for Zod app')
|
||||
.setVersion('1.0')
|
||||
.addBearerAuth({ in: 'header', type: 'http' })
|
||||
.build();
|
||||
|
||||
return SwaggerModule.createDocument(app, swaggerConfig);
|
||||
}
|
||||
|
||||
bootstrap();
|
||||
Reference in New Issue
Block a user