initial
This commit is contained in:
44
apps/api/src/main.ts
Normal file
44
apps/api/src/main.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'reflect-metadata';
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import express, { NextFunction, Request, Response } from 'express';
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule, { bodyParser: false });
|
||||
|
||||
app.enableCors({
|
||||
origin: process.env.PUBLIC_WEB_URL ?? 'http://localhost:4200',
|
||||
credentials: true,
|
||||
});
|
||||
|
||||
const jsonParser = express.json();
|
||||
const formParser = express.urlencoded({ extended: false });
|
||||
app.use((request: Request, response: Response, next: NextFunction) => {
|
||||
if (request.path.startsWith('/oidc') || request.path.startsWith('/.well-known')) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
jsonParser(request, response, (jsonError) => {
|
||||
if (jsonError) {
|
||||
next(jsonError);
|
||||
return;
|
||||
}
|
||||
formParser(request, response, next);
|
||||
});
|
||||
});
|
||||
|
||||
app.useGlobalPipes(
|
||||
new ValidationPipe({
|
||||
whitelist: true,
|
||||
forbidNonWhitelisted: true,
|
||||
transform: true,
|
||||
}),
|
||||
);
|
||||
|
||||
const port = Number(process.env.API_PORT ?? 3000);
|
||||
await app.listen(port);
|
||||
}
|
||||
|
||||
void bootstrap();
|
||||
Reference in New Issue
Block a user