* chore: Billing Service * chore: others * chore: don't type * chore: typo * chore: use proper wh secret * chore: updates * chore: lockfile * chore: docs and comment out * chore: updates and include plan * chore: config * chore: bring back alias * chore: update lockfile * chore: refactor * chore: default none plan in db * chore: read from env vars * chore: feedback * chore: remove json config * chore: proper type
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import type { AppConfig } from "@/config/type";
|
|
import { Logger } from "@nestjs/common";
|
|
import { ConfigService } from "@nestjs/config";
|
|
import { NestFactory } from "@nestjs/core";
|
|
import type { NestExpressApplication } from "@nestjs/platform-express";
|
|
import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";
|
|
import "dotenv/config";
|
|
import * as fs from "fs";
|
|
import { Server } from "http";
|
|
import { WinstonModule } from "nest-winston";
|
|
|
|
import { bootstrap } from "./app";
|
|
import { AppModule } from "./app.module";
|
|
import { loggerConfig } from "./lib/logger";
|
|
|
|
const run = async () => {
|
|
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
|
|
logger: WinstonModule.createLogger(loggerConfig()),
|
|
bodyParser: false,
|
|
});
|
|
|
|
const logger = new Logger("App");
|
|
|
|
try {
|
|
bootstrap(app);
|
|
const port = app.get(ConfigService<AppConfig, true>).get("api.port", { infer: true });
|
|
if (process.env.SKIP_DOCS_GENERATION !== "1") {
|
|
void generateSwagger(app);
|
|
}
|
|
await app.listen(port);
|
|
logger.log(`Application started on port: ${port}`);
|
|
} catch (error) {
|
|
console.error(error);
|
|
logger.error("Application crashed", {
|
|
error,
|
|
});
|
|
}
|
|
};
|
|
|
|
async function generateSwagger(app: NestExpressApplication<Server>) {
|
|
const logger = new Logger("App");
|
|
logger.log(`Generating Swagger documentation...\n`);
|
|
|
|
const config = new DocumentBuilder().setTitle("Cal.com v2 API").build();
|
|
|
|
const document = SwaggerModule.createDocument(app, config);
|
|
|
|
const outputFile = "./swagger/documentation.json";
|
|
|
|
if (fs.existsSync(outputFile)) {
|
|
fs.unlinkSync(outputFile);
|
|
}
|
|
|
|
fs.writeFileSync(outputFile, JSON.stringify(document, null, 2), { encoding: "utf8" });
|
|
SwaggerModule.setup("docs", app, document, {
|
|
customCss: ".swagger-ui .topbar { display: none }",
|
|
});
|
|
|
|
logger.log(`Swagger documentation available in the "/docs" endpoint\n`);
|
|
}
|
|
|
|
run().catch((error: Error) => {
|
|
console.error("Failed to start Cal Platform API", { error: error.stack });
|
|
process.exit(1);
|
|
});
|