import { NestFactory } from '@nestjs/core'; import { NestExpressApplication } from '@nestjs/platform-express'; import { AppModule } from './app.module'; import * as session from 'express-session'; import * as passport from 'passport'; import * as flash from 'express-flash'; import * as expressLayouts from 'express-ejs-layouts'; import * as methodOverride from 'method-override'; import * as path from 'path'; // eslint-disable-next-line @typescript-eslint/no-var-requires const SQLiteStore = require('connect-sqlite3')(session); async function bootstrap() { const app = await NestFactory.create(AppModule); // Static assets app.useStaticAssets(path.join(__dirname, '..', 'public')); // Views app.setBaseViewsDir(path.join(__dirname, '..', 'views')); app.setViewEngine('ejs'); // Layouts app.use(expressLayouts); app.set('layout', 'layout'); // Method override app.use(methodOverride('_method')); // Body parsing (built-in in NestJS, but ensuring extended urlencoded) app.useBodyParser('urlencoded', { extended: true }); // Session app.use( session({ store: new SQLiteStore({ db: 'sessions.db', dir: './data' }), secret: process.env.SECRET_KEY || 'secret', resave: false, saveUninitialized: false, cookie: { maxAge: 30 * 24 * 60 * 60 * 1000 }, // 30 days }), ); // Passport app.use(passport.initialize()); app.use(passport.session()); // Flash app.use(flash()); // Global variables (helper functions) const expressApp = app.getHttpAdapter().getInstance(); expressApp.locals.round = Math.round; const PORT = process.env.PORT || 3000; await app.listen(PORT, '0.0.0.0'); console.log(`Application is running on: ${await app.getUrl()}`); } bootstrap();