Is this a bad practices? If so, how to do ?
const logger = new Logger("Bootstrap");
async function bootstrap(): Promise<void> {
const tmpApp = await NestFactory.createApplicationContext(AppModule);
const configService =
tmpApp.get<ConfigService<EnvGlobalConfig, true>>(ConfigService);
const { nodeEnv, port } =
configService.get<EnvGlobalConfig["server"]>("server");
await tmpApp.close();
let app: NestExpressApplication;
if (nodeEnv === "production") {
app = await NestFactory.create<NestExpressApplication>(AppModule);
app.use(helmet());
} else {
app = await NestFactory.create<NestExpressApplication>(AppModule, {
httpsOptions: {
key: readFileSync(join(__dirname, "..", "secrets", "dev-key.pem")),
cert: readFileSync(join(__dirname, "..", "secrets", "dev-cert.pem")),
},
});
}
app.use(cookieParser());
app.useStaticAssets(join(__dirname, "..", "public"));
app.setBaseViewsDir(join(__dirname, "..", "views"));
app.setViewEngine("hbs");
await app.listen(port);
logger.log(`Application running in ${nodeEnv} mode on port ${port}`);
logger.log(`Application URL: http://localhost:${port}`);
}
void bootstrap();