87 lines
2.5 KiB
TypeScript
87 lines
2.5 KiB
TypeScript
import { loadSwagger } from '@gitroom/helpers/swagger/load.swagger';
|
|
import { json } from 'express';
|
|
|
|
process.env.TZ = 'UTC';
|
|
|
|
import cookieParser from 'cookie-parser';
|
|
import { Logger, ValidationPipe } from '@nestjs/common';
|
|
import { NestFactory } from '@nestjs/core';
|
|
import { AppModule } from './app.module';
|
|
|
|
import { initializeSentry } from '@gitroom/nestjs-libraries/sentry/initialize.sentry';
|
|
initializeSentry('backend', true);
|
|
|
|
import { SubscriptionExceptionFilter } from '@gitroom/backend/services/auth/permissions/subscription.exception';
|
|
import { HttpExceptionFilter } from '@gitroom/nestjs-libraries/services/exception.filter';
|
|
import { ConfigurationChecker } from '@gitroom/helpers/configuration/configuration.checker';
|
|
import { startMcp } from '@gitroom/nestjs-libraries/chat/start.mcp';
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create(AppModule, {
|
|
rawBody: true,
|
|
cors: {
|
|
...(!process.env.NOT_SECURED ? { credentials: true } : {}),
|
|
allowedHeaders: ['Content-Type', 'Authorization'],
|
|
exposedHeaders: [
|
|
'reload',
|
|
'onboarding',
|
|
'activate',
|
|
...(process.env.NOT_SECURED ? ['auth', 'showorg', 'impersonate'] : []),
|
|
],
|
|
origin: [
|
|
process.env.FRONTEND_URL,
|
|
'http://localhost:6274',
|
|
...(process.env.MAIN_URL ? [process.env.MAIN_URL] : []),
|
|
],
|
|
},
|
|
});
|
|
|
|
await startMcp(app);
|
|
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
transform: true,
|
|
})
|
|
);
|
|
|
|
app.use('/copilot', (req: any, res: any, next: any) => {
|
|
json({ limit: '50mb' })(req, res, next);
|
|
});
|
|
|
|
app.use(cookieParser());
|
|
app.useGlobalFilters(new SubscriptionExceptionFilter());
|
|
app.useGlobalFilters(new HttpExceptionFilter());
|
|
|
|
loadSwagger(app);
|
|
|
|
const port = process.env.PORT || 3000;
|
|
|
|
try {
|
|
await app.listen(port);
|
|
|
|
checkConfiguration(); // Do this last, so that users will see obvious issues at the end of the startup log without having to scroll up.
|
|
|
|
Logger.log(`🚀 Backend is running on: http://localhost:${port}`);
|
|
} catch (e) {
|
|
Logger.error(`Backend failed to start on port ${port}`, e);
|
|
}
|
|
}
|
|
|
|
function checkConfiguration() {
|
|
const checker = new ConfigurationChecker();
|
|
checker.readEnvFromProcess();
|
|
checker.check();
|
|
|
|
if (checker.hasIssues()) {
|
|
for (const issue of checker.getIssues()) {
|
|
Logger.warn(issue, 'Configuration issue');
|
|
}
|
|
|
|
Logger.warn('Configuration issues found: ' + checker.getIssuesCount());
|
|
} else {
|
|
Logger.log('Configuration check completed without any issues.');
|
|
}
|
|
}
|
|
|
|
bootstrap();
|