"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const common_1 = require("@moonlightjs/common");
const common_2 = require("@nestjs/common");
const core_1 = require("@nestjs/core");
const dotenv = require("dotenv");
const httpContext = require("express-http-context");
const moduleAlias = require("module-alias");
const app_module_1 = require("./app.module");
const setup_swagger_1 = require("./setup-swagger");
dotenv.config({ override: true });
moduleAlias.addAliases({
    '@modules': `${__dirname}/modules`,
    '@src': `${__dirname}`,
});
const PORT = process.env.PORT || 1999;
async function bootstrap() {
    const app = await core_1.NestFactory.create(app_module_1.AppModule);
    const prismaService = app.get(common_1.PrismaService);
    await prismaService.enableShutdownHooks(app);
    app.useGlobalPipes(new common_2.ValidationPipe());
    app.useGlobalPipes(new common_1.FilterPipe());
    app.enableCors();
    app.use(httpContext.middleware);
    app.use('/api', common_1.GlobalApiLoggerMiddleware);
    app.useGlobalInterceptors(new common_1.TransformInterceptor());
    app.useGlobalInterceptors(new common_1.ResponseInterceptor());
    app.useGlobalFilters(new common_1.GlobalExceptionFilter());
    app.setGlobalPrefix('api');
    app.enableVersioning({
        type: common_2.VersioningType.URI,
    });
    const { httpAdapter } = app.get(core_1.HttpAdapterHost);
    app.useGlobalFilters(new common_1.PrismaClientExceptionFilter(httpAdapter));
    if ((0, common_1.isDevelopment)()) {
        (0, setup_swagger_1.setupSwagger)(app);
    }
    await app.listen(PORT, () => {
        console.log(`🚀 Server ready at http://localhost:${PORT}`);
        if ((0, common_1.isDevelopment)()) {
            console.log(`🚀 Swagger at http://localhost:${PORT}/api/docs`);
        }
    });
}
bootstrap().then();
//# sourceMappingURL=main.js.map