42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { NestFactory, Reflector } from '@nestjs/core';
|
|
import { ValidationPipe } from '@nestjs/common';
|
|
import { AppModule } from './app.module';
|
|
import { JwtAuthPublicGuard } from './modules/auth/jwt-auth-public.guard';
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create(AppModule);
|
|
|
|
const allowedOrigins = [
|
|
process.env.FRONTEND_URL ?? 'http://localhost:5173',
|
|
process.env.PWA_URL ?? 'http://localhost:5174',
|
|
process.env.STRAPI_URL ?? 'http://localhost:1337',
|
|
];
|
|
|
|
app.enableCors({
|
|
origin: allowedOrigins,
|
|
credentials: true,
|
|
});
|
|
|
|
app.setGlobalPrefix('api/v1');
|
|
|
|
// Apply global validation pipe
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
whitelist: true,
|
|
transform: true,
|
|
forbidNonWhitelisted: true,
|
|
}),
|
|
);
|
|
|
|
// Apply global authentication guard
|
|
const reflector = app.get(Reflector);
|
|
app.useGlobalGuards(new JwtAuthPublicGuard(reflector));
|
|
|
|
const port = process.env.PORT ?? 3000;
|
|
const host = '0.0.0.0'; // Bind to all interfaces for Docker
|
|
await app.listen(port, host);
|
|
|
|
console.log(`Application is running on: http://${host}:${port}`);
|
|
}
|
|
void bootstrap();
|