Menyelesaikan object user dan init base
This commit is contained in:
+48
-1
@@ -1 +1,48 @@
|
||||
// placeholder main.ts
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
|
||||
const config = app.get(ConfigService);
|
||||
|
||||
app.setGlobalPrefix('api');
|
||||
|
||||
app.useGlobalPipes(
|
||||
new ValidationPipe({
|
||||
whitelist: true,
|
||||
transform: true,
|
||||
forbidNonWhitelisted: true,
|
||||
}),
|
||||
);
|
||||
|
||||
app.enableCors();
|
||||
|
||||
const swaggerEnabled =
|
||||
config.get<string>('SWAGGER_ENABLED') === 'true';
|
||||
|
||||
if (swaggerEnabled) {
|
||||
const swaggerConfig = new DocumentBuilder()
|
||||
.setTitle('RayLab Core API')
|
||||
.setDescription('RayLab Core REST API')
|
||||
.setVersion('1.0.0')
|
||||
.addBearerAuth()
|
||||
.build();
|
||||
|
||||
const document = SwaggerModule.createDocument(app, swaggerConfig);
|
||||
|
||||
SwaggerModule.setup('docs', app, document);
|
||||
}
|
||||
|
||||
const port = config.get<number>('PORT') || 3000;
|
||||
|
||||
await app.listen(port);
|
||||
|
||||
console.log(`Server running on http://localhost:${port}`);
|
||||
}
|
||||
|
||||
bootstrap();
|
||||
Reference in New Issue
Block a user