Skip to content
Snippets Groups Projects
main.ts 1009 B
/**
 * This is not a production server yet!
 * This is only a minimal backend to get started.
 */

import { Logger } from "@nestjs/common";
import { NestFactory } from "@nestjs/core";

import { AppModule } from "./app/app.module";
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
import * as fs from "fs";

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const globalPrefix = "api";
  app.setGlobalPrefix(globalPrefix);
  const port = process.env.AGENT_PORT || 3001;
  app.enableShutdownHooks();

  const config = new DocumentBuilder()
    .setTitle("Agent")
    .setDescription("Agent API")
    .setVersion("1.0")
    .build();

  const document = SwaggerModule.createDocument(app, config);
  fs.writeFileSync("./agent-swagger.json", JSON.stringify(document));
  SwaggerModule.setup("api", app, document);

  await app.listen(port, "0.0.0.0");
  Logger.log(
    `🚀 Application is running on: http://0.0.0.0:${port}/${globalPrefix}`,
  );
}

bootstrap();