Skip to content

Commit 5f317b8

Browse files
serve vercel
1 parent 1ca5845 commit 5f317b8

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/lib/index.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
const express = require('express');
22
const bodyParser = require('body-parser');
33
const cors = require('cors');
4-
const path = require('path');
54
const swaggerUi = require('swagger-ui-express');
5+
const path = require('path');
66
const openApiSpec = require('../swagger/openapi.json');
77

88
const app = express();
9-
const PORT = process.env.PORT || 3000;
109

1110
app.use(cors());
1211
app.use(bodyParser.json());
@@ -20,16 +19,20 @@ app.use('/api/projects', projectRoutes);
2019
app.use('/api/tasks', taskRoutes);
2120
app.use('/api/users', userRoutes);
2221

23-
// Swagger UI
22+
// Serve Swagger UI
2423
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(openApiSpec));
2524

26-
// OpenAPI JSON
25+
// Serve the OpenAPI JSON
2726
app.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

Comments
 (0)