- Add Dockerfile and docker-compose.yml for containerized deployment - Update server to listen on all network interfaces for Docker compatibility - Add .dockerignore to exclude unnecessary files from build context - Enhance dashboard controller with additional user data, trends, and suggestions - Update package.json scripts for proper Docker build workflow
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
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<NestExpressApplication>(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();
|