build: add TypeScript configuration and generate declaration files
- Add tsconfig.json for TypeScript compilation with declaration and source map generation - Generate .d.ts declaration files for all modules, services, controllers, and models - Update package.json with NestJS dependencies and TypeScript development tools - Include database files in the distribution output for persistence
This commit is contained in:
60
src/main.ts
Normal file
60
src/main.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
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);
|
||||
console.log(`Application is running on: ${await app.getUrl()}`);
|
||||
}
|
||||
bootstrap();
|
||||
Reference in New Issue
Block a user