-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
50 lines (42 loc) · 1.1 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const express = require('express');
const app = express();
const swaggerUi = require('swagger-ui-express');
const swaggerJsdoc = require('swagger-jsdoc');
const port = process.env.PORT || 3000;
// Swagger configuration
const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'Your API Documentation',
version: '1.0.0',
description: 'API documentation for your project',
},
servers: [
{
url: `http://localhost:${port}`, // Replace with your server URL
},
],
},
apis: ['./routes/*.js'], // Specify the path to your route files
};
const specs = swaggerJsdoc(options);
// Middleware to serve Swagger documentation
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs));
// Other middleware and route setup
app.use(express.json());
// Add your routes here
// Error handling middleware
app.use((err, req, res, next) => {
res.status(err.status || 500);
res.json({
error: {
message: err.message,
},
});
});
// Start the server
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
module.exports = app;