@@ -6,9 +6,11 @@ import express, { ErrorRequestHandler } from 'express';
66import http from 'http' ;
77import cors from 'cors' ;
88import rateLimit from 'express-rate-limit' ;
9+ import swaggerUi from 'swagger-ui-express' ;
910import api from './api' ;
1011import { migrate } from './migrations' ;
1112import { AppError } from '@/utils' ;
13+ import { swaggerSpec } from './services/swagger' ;
1214
1315// Validate required environment variables
1416const requiredEnvVars = [ 'JWT_SECRET' , 'MONGODB_URI' ] ;
@@ -64,6 +66,22 @@ app.get('/health', (req, res) => {
6466 } ) ;
6567} ) ;
6668
69+ // Swagger documentation
70+ app . use (
71+ '/docs' ,
72+ swaggerUi . serve ,
73+ swaggerUi . setup ( swaggerSpec , {
74+ customCss : '.swagger-ui .topbar { display: none }' ,
75+ customSiteTitle : 'Zoomment API Docs'
76+ } )
77+ ) ;
78+
79+ // Swagger JSON endpoint
80+ app . get ( '/docs.json' , ( req , res ) => {
81+ res . setHeader ( 'Content-Type' , 'application/json' ) ;
82+ res . send ( swaggerSpec ) ;
83+ } ) ;
84+
6785app . use ( '/api' , api ) ;
6886
6987// Error handler
@@ -87,6 +105,7 @@ const server = http.createServer(app);
87105setImmediate ( ( ) => {
88106 server . listen ( process . env . PORT , ( ) => {
89107 console . log ( 'Express server listening on http://localhost:%s/' , process . env . PORT ) ;
108+ console . log ( 'API Docs available at http://localhost:%s/docs' , process . env . PORT ) ;
90109 } ) ;
91110} ) ;
92111
0 commit comments