11const express = require ( 'express' ) ;
22const bodyParser = require ( 'body-parser' ) ;
33const cors = require ( 'cors' ) ;
4- const path = require ( 'path' ) ;
54const swaggerUi = require ( 'swagger-ui-express' ) ;
5+ const path = require ( 'path' ) ;
66const openApiSpec = require ( '../swagger/openapi.json' ) ;
77
88const app = express ( ) ;
9- const PORT = process . env . PORT || 3000 ;
109
1110app . use ( cors ( ) ) ;
1211app . use ( bodyParser . json ( ) ) ;
@@ -20,16 +19,20 @@ app.use('/api/projects', projectRoutes);
2019app . use ( '/api/tasks' , taskRoutes ) ;
2120app . use ( '/api/users' , userRoutes ) ;
2221
23- // Swagger UI
22+ // Serve Swagger UI
2423app . use ( '/api-docs' , swaggerUi . serve , swaggerUi . setup ( openApiSpec ) ) ;
2524
26- // OpenAPI JSON
25+ // Serve the OpenAPI JSON
2726app . get ( '/openapi.json' , ( req , res ) => {
2827 res . sendFile ( path . join ( __dirname , '../swagger/openapi.json' ) ) ;
2928} ) ;
3029
31- app . listen ( PORT , ( ) => {
32- console . log ( `Server is running on http://localhost:${ PORT } ` ) ;
33- console . log ( `API documentation available at http://localhost:${ PORT } /api-docs` ) ;
34- console . log ( `OpenAPI JSON available at http://localhost:${ PORT } /openapi.json` ) ;
35- } ) ;
30+ // Export the app for Vercel or start the server locally
31+ if ( process . env . NODE_ENV !== 'production' ) {
32+ const PORT = process . env . PORT || 3000 ;
33+ app . listen ( PORT , ( ) => {
34+ console . log ( `Server is running locally at http://localhost:${ PORT } ` ) ;
35+ } ) ;
36+ }
37+
38+ module . exports = app ;
0 commit comments