mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import { RequestContextMiddleware } from '@app/common/middleware/request-context.middleware';
|
|
import { SeederService } from '@app/common/seed/services/seeder.service';
|
|
import { Logger, ValidationPipe } from '@nestjs/common';
|
|
import { NestFactory } from '@nestjs/core';
|
|
import { json, urlencoded } from 'body-parser';
|
|
import rateLimit from 'express-rate-limit';
|
|
import helmet from 'helmet';
|
|
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
|
|
import { setupSwaggerAuthentication } from '../libs/common/src/util/user-auth.swagger.utils';
|
|
import { AppModule } from './app.module';
|
|
import { HttpExceptionFilter } from './common/filters/http-exception/http-exception.filter';
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create(AppModule);
|
|
|
|
app.enableCors();
|
|
|
|
// Set the body parser limit to 1 MB
|
|
app.use(json({ limit: '1mb' }));
|
|
app.use(urlencoded({ limit: '1mb', extended: true }));
|
|
app.useGlobalFilters(new HttpExceptionFilter());
|
|
|
|
app.use(new RequestContextMiddleware().use);
|
|
|
|
app.use(
|
|
rateLimit({
|
|
windowMs: 5 * 60 * 1000,
|
|
max: 500,
|
|
}),
|
|
);
|
|
|
|
app.use((req, res, next) => {
|
|
console.log('Real IP:', req.ip);
|
|
next();
|
|
});
|
|
|
|
// app.getHttpAdapter().getInstance().set('trust proxy', 1);
|
|
|
|
app.use(
|
|
helmet({
|
|
contentSecurityPolicy: false,
|
|
}),
|
|
);
|
|
|
|
setupSwaggerAuthentication(app);
|
|
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
transform: true, // Auto-transform payloads to their DTO instances.
|
|
transformOptions: {
|
|
enableImplicitConversion: true, // Convert incoming payloads to their DTO instances if possible.
|
|
},
|
|
}),
|
|
);
|
|
|
|
const seederService = app.get(SeederService);
|
|
const logger = app.get<Logger>(WINSTON_MODULE_NEST_PROVIDER);
|
|
|
|
try {
|
|
await seederService.seed();
|
|
logger.log('Seeding complete!');
|
|
} catch (error) {
|
|
logger.error('Seeding failed!', error.stack || error);
|
|
}
|
|
|
|
logger.log('Starting auth at port ...', process.env.PORT || 4000);
|
|
await app.listen(process.env.PORT || 4000);
|
|
}
|
|
bootstrap();
|