|
import { Logger } from "@nestjs/common"; |
|
import { ConfigService } from "@nestjs/config"; |
|
import { NestFactory } from "@nestjs/core"; |
|
import type { NestExpressApplication } from "@nestjs/platform-express"; |
|
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger"; |
|
import cookieParser from "cookie-parser"; |
|
import session from "express-session"; |
|
import helmet from "helmet"; |
|
import { patchNestJsSwagger } from "nestjs-zod"; |
|
|
|
import { AppModule } from "./app.module"; |
|
import type { Config } from "./config/schema"; |
|
|
|
patchNestJsSwagger(); |
|
|
|
async function bootstrap() { |
|
const app = await NestFactory.create<NestExpressApplication>(AppModule, { |
|
logger: process.env.NODE_ENV === "development" ? ["debug"] : ["error", "warn", "log"], |
|
}); |
|
|
|
const configService = app.get(ConfigService<Config>); |
|
|
|
const accessTokenSecret = configService.getOrThrow("ACCESS_TOKEN_SECRET"); |
|
const publicUrl = configService.getOrThrow("PUBLIC_URL"); |
|
const isHTTPS = publicUrl.startsWith("https://") ?? false; |
|
|
|
|
|
app.use(cookieParser()); |
|
|
|
|
|
app.use( |
|
session({ |
|
resave: false, |
|
saveUninitialized: false, |
|
secret: accessTokenSecret, |
|
cookie: { httpOnly: true, secure: isHTTPS }, |
|
}), |
|
); |
|
|
|
|
|
app.enableCors({ credentials: true, origin: isHTTPS }); |
|
|
|
|
|
if (isHTTPS) app.use(helmet({ contentSecurityPolicy: false })); |
|
|
|
|
|
const globalPrefix = "api"; |
|
app.setGlobalPrefix(globalPrefix); |
|
|
|
|
|
app.enableShutdownHooks(); |
|
|
|
|
|
|
|
const config = new DocumentBuilder() |
|
.setTitle("Reactive Resume") |
|
.setDescription( |
|
"Reactive Resume is a free and open source resume builder that's built to make the mundane tasks of creating, updating and sharing your resume as easy as 1, 2, 3.", |
|
) |
|
.addCookieAuth("Authentication", { type: "http", in: "cookie", scheme: "Bearer" }) |
|
.setVersion("4.0.0") |
|
.build(); |
|
const document = SwaggerModule.createDocument(app, config); |
|
SwaggerModule.setup("docs", app, document); |
|
|
|
|
|
const port = configService.get<number>("PORT") ?? 3000; |
|
|
|
await app.listen(port); |
|
|
|
Logger.log(`๐ Server is up and running on port ${port}`, "Bootstrap"); |
|
} |
|
|
|
|
|
void bootstrap(); |
|
|