first commit
This commit is contained in:
71
src/main.ts
Normal file
71
src/main.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
import { Logger } from 'nestjs-pino';
|
||||
import { NestExpressApplication } from '@nestjs/platform-express';
|
||||
import * as helmet from 'helmet';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import { join } from 'node:path';
|
||||
import { existsSync } from 'node:fs';
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap(): Promise<void> {
|
||||
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
|
||||
bufferLogs: true,
|
||||
});
|
||||
|
||||
const logger = app.get(Logger);
|
||||
app.useLogger(logger);
|
||||
|
||||
app.use(helmet.default({ contentSecurityPolicy: false }));
|
||||
app.use(cookieParser());
|
||||
|
||||
app.enableCors({
|
||||
origin: (process.env.CORS_ORIGINS ?? 'http://localhost:3000').split(','),
|
||||
credentials: true,
|
||||
});
|
||||
|
||||
const viewsPath = join(process.cwd(), 'views');
|
||||
if (existsSync(viewsPath)) {
|
||||
app.setBaseViewsDir(viewsPath);
|
||||
app.setViewEngine('ejs');
|
||||
}
|
||||
|
||||
const publicPath = join(process.cwd(), 'public');
|
||||
if (existsSync(publicPath)) {
|
||||
app.useStaticAssets(publicPath);
|
||||
}
|
||||
|
||||
app.setGlobalPrefix('api', {
|
||||
exclude: [
|
||||
'/',
|
||||
'/login',
|
||||
'/register',
|
||||
'/profile',
|
||||
'/admin',
|
||||
'/admin/users',
|
||||
'/admin/clients',
|
||||
'/metrics',
|
||||
],
|
||||
});
|
||||
|
||||
app.useGlobalPipes(
|
||||
new ValidationPipe({
|
||||
whitelist: true,
|
||||
forbidNonWhitelisted: true,
|
||||
transform: true,
|
||||
}),
|
||||
);
|
||||
|
||||
const trustProxy = parseInt(process.env.TRUST_PROXY ?? '1', 10);
|
||||
|
||||
const instance: any = app.getHttpAdapter().getInstance();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
||||
instance.set('trust proxy', trustProxy);
|
||||
|
||||
const port = parseInt(process.env.PORT ?? '3000', 10);
|
||||
const host = process.env.HOST ?? '0.0.0.0';
|
||||
|
||||
await app.listen(port, host);
|
||||
logger.log(`SSO service listening on http://${host}:${port}`);
|
||||
}
|
||||
void bootstrap();
|
||||
Reference in New Issue
Block a user