-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
43 lines (37 loc) · 975 Bytes
/
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
const express = require('express');
const cors = require('cors');
const swaggerUI = require('swagger-ui-express');
const port = process.env.PORT || 3000;
const orders = require('./routes/orders');
const suppliers = require('./routes/suppliers');
const swaggerJSDoc = require('swagger-jsdoc');
require('dotenv').config();
const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'Library API',
version: '1.0.0',
description: 'simple express API',
},
servers: [
{
url: 'http://localhost:3000',
},
],
},
apis: ['./routes/*.js'],
};
const specs = swaggerJSDoc(options);
const app = express();
app.use(cors());
app.use(express.json());
app.use('/api-docs', swaggerUI.serve, swaggerUI.setup(specs));
app.use('/orders', orders);
app.use('/suppliers', suppliers);
app.get('/', (req, res) => {
res.redirect('/api-docs');
});
app.listen(port, () => {
console.info(`Server started on port ${port}`);
});