Refactor multiple modules to improve dependency management by adding missing imports (e.g., `AuthModule`, `CryptoModule`) and ensuring essential services and repositories are exported. Update Dockerfile for better build and runtime efficiency, improve CORS handling, and enhance validation with updates to DTOs. Include package.json refinements for dependency organization.
70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
import { Logger, ValidationPipe } from "@nestjs/common";
|
|
import { ConfigService } from "@nestjs/config";
|
|
import { NestFactory } from "@nestjs/core";
|
|
import * as Sentry from "@sentry/nestjs";
|
|
import { nodeProfilingIntegration } from "@sentry/profiling-node";
|
|
import helmet from "helmet";
|
|
import { AppModule } from "./app.module";
|
|
import { AllExceptionsFilter } from "./common/filters/http-exception.filter";
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create(AppModule);
|
|
const configService = app.get(ConfigService);
|
|
const logger = new Logger("Bootstrap");
|
|
|
|
const sentryDsn = configService.get<string>("SENTRY_DSN");
|
|
if (sentryDsn) {
|
|
Sentry.init({
|
|
dsn: sentryDsn,
|
|
integrations: [nodeProfilingIntegration()],
|
|
tracesSampleRate: 1.0,
|
|
profilesSampleRate: 1.0,
|
|
sendDefaultPii: false, // RGPD
|
|
});
|
|
}
|
|
|
|
// Sécurité
|
|
app.use(
|
|
helmet({
|
|
crossOriginResourcePolicy: { policy: "cross-origin" },
|
|
}),
|
|
);
|
|
const corsEnabled = Boolean(configService.get<boolean>("ENABLE_CORS"));
|
|
if (corsEnabled) {
|
|
const domainName = configService.get<string>("CORS_DOMAIN_NAME");
|
|
app.enableCors({
|
|
origin: (origin, callback) => {
|
|
if (!origin || domainName === "*") {
|
|
callback(null, true);
|
|
return;
|
|
}
|
|
|
|
const allowedOrigins = domainName?.split(",").map((o) => o.trim()) || [];
|
|
if (allowedOrigins.includes(origin)) {
|
|
callback(null, true);
|
|
} else {
|
|
callback(null, false);
|
|
}
|
|
},
|
|
credentials: true,
|
|
});
|
|
}
|
|
|
|
// Validation Globale
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
whitelist: true,
|
|
forbidNonWhitelisted: true,
|
|
transform: true,
|
|
}),
|
|
);
|
|
|
|
// Filtre d'exceptions global
|
|
app.useGlobalFilters(new AllExceptionsFilter());
|
|
|
|
const port = configService.get<number>("PORT") || 3000;
|
|
await app.listen(port);
|
|
logger.log(`Application is running on: http://localhost:${port}`);
|
|
}
|
|
bootstrap().then();
|