feat: /api/channels endpoint, /api namespace, Scalar at root (v0.1.0) (#2)
feat: /api/channels endpoint, /api namespace, Scalar at root (v0.1.0) — closes #1
This commit was merged in pull request #2.
This commit is contained in:
+23
-1
@@ -1,9 +1,31 @@
|
||||
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);
|
||||
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
||||
app.enableShutdownHooks();
|
||||
app.setGlobalPrefix('api');
|
||||
|
||||
// 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.',
|
||||
)
|
||||
.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();
|
||||
|
||||
Reference in New Issue
Block a user