import { NestFactory } from '@nestjs/core'; import type { NestExpressApplication } from '@nestjs/platform-express'; import type { RequestHandler } from 'express'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; import { apiReference } from '@scalar/nestjs-api-reference'; import * as pkg from '../package.json'; import { AppModule } from './app.module.js'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.enableShutdownHooks(); // 'mcp' is excluded so the MCP endpoint lives at /mcp, not /api/mcp (like Scalar at /) app.setGlobalPrefix('api', { exclude: ['mcp'] }); // Scalar API docs at / (OpenAPI JSON at /docs-json), outside the api prefix. const docConfig = new DocumentBuilder() .setTitle('MeshBot API') .setDescription( 'Meshtastic bridge bot: status, send text messages, list device channels and known nodes.', ) .addTag('Mesh', 'Meshtastic bridge control and telemetry') .setVersion(pkg.version) .build(); const document = SwaggerModule.createDocument(app, docConfig); const http = app.getHttpAdapter().getInstance(); http.get('/docs-json', (_req, res) => { res.json(document); }); http.get('/', apiReference({ url: '/docs-json' }) as RequestHandler); await app.listen(process.env.PORT ?? 3000); } bootstrap();