0% found this document useful (0 votes)
9 views1 page

Main

This document outlines the bootstrap process for a NestJS application, including configuration for static file serving, CORS, body parsing, and Swagger documentation. It sets up global prefixes and initializes the application to listen on a specified port. Environment variables are utilized for configuration, with default values provided where necessary.

Uploaded by

optetrax
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Main

This document outlines the bootstrap process for a NestJS application, including configuration for static file serving, CORS, body parsing, and Swagger documentation. It sets up global prefixes and initializes the application to listen on a specified port. Environment variables are utilized for configuration, with default values provided where necessary.

Uploaded by

optetrax
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import { NestFactory } from '@nestjs/core';

import { AppModule } from './app.module';


import * as dotenv from 'dotenv';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import * as bodyParser from 'body-parser';
import * as cookieParser from 'cookie-parser';
import { NestExpressApplication } from '@nestjs/platform-express';
import * as path from 'path';
import * as express from 'express';
import * as fs from 'fs';

dotenv.config();

async function bootstrap() {


const app = await NestFactory.create<NestExpressApplication>(AppModule);
const BASE_URI = process.env.BASE_URI || 'http://localhost:8000';

app.setGlobalPrefix('data');

// Serve static assets


app.use('/static', express.static(path.join(__dirname, '..', 'public')));
console.log(`🚀 Static files available at: ${BASE_URI}/static`);

app.enableCors({
origin: ["http://localhost:5173", "http://localhost:3000",
"http://localhost:5174"],
methods: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'],
allowedHeaders: ['Content-Type', 'Authorization', 'ngrok-skip-browser-
warning'],
credentials: true,
});

app.use(
bodyParser.json({ limit: '50mb' }),
bodyParser.urlencoded({ limit: '50mb', extended: true }),
);
app.use(cookieParser());

// Swagger setup
const config = new DocumentBuilder()
.setTitle('API Documentation')
.setDescription('The API description for our NestJS app')
.setVersion('1.0')
.addTag('Users')
.addTag('Invitation')
.build();

const document = SwaggerModule.createDocument(app, config);


SwaggerModule.setup('api', app, document);

// Listen on port from environment variables or default to 4000


const port = process.env.PORT || 8000;
await app.listen(port);

console.log(`🚀 Application is running on: ${BASE_URI}`);


}

bootstrap();

You might also like