-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
39 lines (32 loc) · 855 Bytes
/
index.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
import '@babel/polyfill';
import express from 'express';
import bodyParser from 'body-parser';
import cors from 'cors';
import morgan from 'morgan';
import router from './routes';
import swaggerUi from 'swagger-ui-express';
import swaggerDocument from './swagger.json';
// express app
const app = express();
app.use(cors());
// body parse configuration
app.use(
bodyParser.urlencoded({
extended: false
})
);
app.use(bodyParser.json());
app.use(morgan('dev'));
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use(router);
// Error handling to catch 404
app.all('*', (_req, res) => {
res.status(404).json({
error: 'address Not found'
});
});
//Starting server
const server = app.listen(process.env.PORT || 3000, () => {
console.log(`Server running on ${server.address().port}`);
});
export default app;