Upload main.ts
Browse files
projects/telegram-send-demo/backend/src/main.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as dns from 'node:dns';
|
| 2 |
+
import { Logger } from '@nestjs/common';
|
| 3 |
+
import { NestFactory } from '@nestjs/core';
|
| 4 |
+
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
| 5 |
+
import { AppModule } from './app.module';
|
| 6 |
+
|
| 7 |
+
dns.setDefaultResultOrder('ipv4first');
|
| 8 |
+
|
| 9 |
+
async function bootstrap(): Promise<void> {
|
| 10 |
+
const app = await NestFactory.create(AppModule);
|
| 11 |
+
|
| 12 |
+
const swaggerConfig = new DocumentBuilder()
|
| 13 |
+
.setTitle('Telegram Notifier API')
|
| 14 |
+
.setDescription('API for sending Telegram notifications and connecting chats.')
|
| 15 |
+
.setVersion('1.0')
|
| 16 |
+
.build();
|
| 17 |
+
const swaggerDocument = SwaggerModule.createDocument(app, swaggerConfig);
|
| 18 |
+
SwaggerModule.setup('api/docs', app, swaggerDocument);
|
| 19 |
+
|
| 20 |
+
const corsOrigins = (process.env.CORS_ORIGINS ?? 'http://localhost:5173')
|
| 21 |
+
.split(',')
|
| 22 |
+
.map((origin) => origin.trim())
|
| 23 |
+
.filter(Boolean);
|
| 24 |
+
|
| 25 |
+
app.enableCors({
|
| 26 |
+
origin: corsOrigins,
|
| 27 |
+
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
|
| 28 |
+
credentials: true,
|
| 29 |
+
});
|
| 30 |
+
app.enableShutdownHooks();
|
| 31 |
+
|
| 32 |
+
const port = Number(process.env.PORT ?? 3000);
|
| 33 |
+
await app.listen(port);
|
| 34 |
+
|
| 35 |
+
Logger.log(`API listening on http://localhost:${port}`, 'Bootstrap');
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
void bootstrap();
|