added initial swagger docs

This commit is contained in:
Joe Arndt 2026-02-13 11:03:31 -06:00
parent f72047b18e
commit b7acc9e352
7 changed files with 80 additions and 16 deletions

View file

@ -1,5 +1,5 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { HealthcheckController } from './healthcheck.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { MerchantsModule } from './merchants/merchants.module';
import { TagsModule } from './tags/tags.module';
@ -40,6 +40,6 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
SubCategoriesModule,
ExpensesModule
],
controllers: [AppController]
controllers: [HealthcheckController]
})
export class AppModule { }

View file

@ -1,7 +1,7 @@
import { Controller, Get } from '@nestjs/common';
@Controller()
export class AppController {
export class HealthcheckController {
@Get('healthcheck')
health() {
return { status: 'healthy' };

View file

@ -1,11 +1,20 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { NestExpressApplication } from '@nestjs/platform-express';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
async function bootstrap(): Promise<void> {
const app = await NestFactory.create<NestExpressApplication>(AppModule);
app.enableCors();
app.setGlobalPrefix(process.env.PREFIX ?? 'common-cents');
const appPrefix = process.env.PREFIX ?? 'common-cents';
const config = new DocumentBuilder()
.setTitle('Common Cents API')
.setDescription('Documentation for Common Cents API')
.setVersion('1.0')
.build();
const documentFactory = () => SwaggerModule.createDocument(app, config);
SwaggerModule.setup(appPrefix + '/docs', app, documentFactory);
app.enableCors(); // TODO: Research if this is worth worrying about
app.setGlobalPrefix(appPrefix);
await app.listen(process.env.PORT ?? 3000);
}
void bootstrap();