62 lines
2.4 KiB
JavaScript
62 lines
2.4 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const common_1 = require("@nestjs/common");
|
|
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
const core_1 = require("@nestjs/core");
|
|
const config_1 = require("@nestjs/config");
|
|
const swagger_1 = require("@nestjs/swagger");
|
|
const app_module_1 = require("./app.module");
|
|
async function bootstrap() {
|
|
const app = await core_1.NestFactory.create(app_module_1.AppModule);
|
|
const config = app.get(config_1.ConfigService);
|
|
const logger = new common_1.Logger('Bootstrap');
|
|
// enable cookie parser so req.cookies is populated
|
|
app.use((0, cookie_parser_1.default)());
|
|
app.setGlobalPrefix('');
|
|
app.useGlobalPipes(new common_1.ValidationPipe({
|
|
whitelist: true,
|
|
transform: true,
|
|
forbidNonWhitelisted: true,
|
|
}));
|
|
// CORS configuration: only allow configured frontend origins and enable credentials
|
|
const allowedOrigins = [];
|
|
const frontend = config.get('FRONTEND_URL');
|
|
const prodFrontend = config.get('PRODUCTION_FRONTEND_URL');
|
|
if (frontend)
|
|
allowedOrigins.push(frontend);
|
|
if (prodFrontend)
|
|
allowedOrigins.push(prodFrontend);
|
|
app.enableCors({
|
|
origin: allowedOrigins,
|
|
credentials: true,
|
|
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
|
|
allowedHeaders: [
|
|
'Content-Type',
|
|
'Authorization',
|
|
'Accept',
|
|
'Origin',
|
|
'X-Requested-With',
|
|
],
|
|
});
|
|
const swaggerEnabled = config.get('SWAGGER_ENABLED') === 'true';
|
|
if (swaggerEnabled) {
|
|
const swaggerConfig = new swagger_1.DocumentBuilder()
|
|
.setTitle('RayLab Core API')
|
|
.setDescription('RayLab Core REST API')
|
|
.setVersion('1.0.0')
|
|
.addBearerAuth()
|
|
.build();
|
|
const document = swagger_1.SwaggerModule.createDocument(app, swaggerConfig);
|
|
swagger_1.SwaggerModule.setup('ApiList', app, document);
|
|
}
|
|
const port = config.get('PORT') || 3000;
|
|
logger.log(`Allowed CORS origins: ${JSON.stringify(allowedOrigins)}`);
|
|
logger.log(`Server listening on port ${port}`);
|
|
await app.listen(port);
|
|
logger.log(`Server running on http://localhost:${port}`);
|
|
}
|
|
bootstrap();
|
|
//# sourceMappingURL=main.js.map
|