2022-10-09 22:30:32 +02:00
|
|
|
import { ClassSerializerInterceptor, ValidationPipe } from "@nestjs/common";
|
|
|
|
import { NestFactory, Reflector } from "@nestjs/core";
|
2022-10-24 12:11:10 +02:00
|
|
|
import { NestExpressApplication } from "@nestjs/platform-express";
|
2023-02-07 11:23:43 +01:00
|
|
|
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
|
2023-01-09 11:43:48 +01:00
|
|
|
import * as bodyParser from "body-parser";
|
2023-01-04 11:54:28 +01:00
|
|
|
import * as cookieParser from "cookie-parser";
|
2022-10-09 22:30:32 +02:00
|
|
|
import * as fs from "fs";
|
|
|
|
import { AppModule } from "./app.module";
|
2023-05-05 11:37:02 +02:00
|
|
|
import { DATA_DIRECTORY } from "./constants";
|
2022-10-24 12:11:10 +02:00
|
|
|
|
2022-10-09 22:30:32 +02:00
|
|
|
async function bootstrap() {
|
2022-10-24 12:11:10 +02:00
|
|
|
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
2022-12-05 16:54:15 +01:00
|
|
|
app.useGlobalPipes(new ValidationPipe({ whitelist: true }));
|
2022-10-09 22:30:32 +02:00
|
|
|
app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)));
|
|
|
|
|
2023-01-13 10:16:35 +01:00
|
|
|
app.use(bodyParser.raw({ type: "application/octet-stream", limit: "20mb" }));
|
2023-01-04 11:54:28 +01:00
|
|
|
app.use(cookieParser());
|
2022-10-24 12:11:10 +02:00
|
|
|
app.set("trust proxy", true);
|
|
|
|
|
2023-05-05 11:37:02 +02:00
|
|
|
await fs.promises.mkdir(`${DATA_DIRECTORY}/uploads/_temp`, {
|
|
|
|
recursive: true,
|
|
|
|
});
|
2022-10-09 22:30:32 +02:00
|
|
|
|
|
|
|
app.setGlobalPrefix("api");
|
2023-02-07 11:23:43 +01:00
|
|
|
|
|
|
|
// Setup Swagger in development mode
|
|
|
|
if (process.env.NODE_ENV == "development") {
|
|
|
|
const config = new DocumentBuilder()
|
|
|
|
.setTitle("Pingvin Share API")
|
|
|
|
.setVersion("1.0")
|
|
|
|
.build();
|
|
|
|
const document = SwaggerModule.createDocument(app, config);
|
|
|
|
SwaggerModule.setup("api/swagger", app, document);
|
|
|
|
}
|
|
|
|
|
2023-05-05 11:37:02 +02:00
|
|
|
await app.listen(parseInt(process.env.PORT) || 8080);
|
2022-10-09 22:30:32 +02:00
|
|
|
}
|
|
|
|
bootstrap();
|