1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-11-15 20:00:33 +01:00
pingvin-share/backend/src/main.ts
2024-04-04 20:54:21 +02:00

47 lines
1.5 KiB
TypeScript

import { ClassSerializerInterceptor, ValidationPipe } from "@nestjs/common";
import { NestFactory, Reflector } from "@nestjs/core";
import { NestExpressApplication } from "@nestjs/platform-express";
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
import * as bodyParser from "body-parser";
import * as cookieParser from "cookie-parser";
import * as fs from "fs";
import { AppModule } from "./app.module";
import { DATA_DIRECTORY } from "./constants";
import { ConfigService } from "./config/config.service";
async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule);
app.useGlobalPipes(new ValidationPipe({ whitelist: true }));
app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)));
const config = app.get<ConfigService>(ConfigService);
app.use(
bodyParser.raw({
type: "application/octet-stream",
limit: `${config.get("share.chunkSize")}B`,
}),
);
app.use(cookieParser());
app.set("trust proxy", true);
await fs.promises.mkdir(`${DATA_DIRECTORY}/uploads/_temp`, {
recursive: true,
});
app.setGlobalPrefix("api");
// 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);
}
await app.listen(parseInt(process.env.PORT) || 8080);
}
bootstrap();