-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
36 lines (29 loc) · 917 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
// import modules
import Express from 'express';
import bodyParser from 'body-parser';
import dotenv from 'dotenv';
import cors from 'cors';
import swaggerUi from 'swagger-ui-express';
import swaggerDocument from './fast.json';
import routes from './server/routes';
dotenv.config();
// declare constants
const app = new Express();
const port = process.env.PORT || 3000;
// declare middleware
app.use(cors());
app.use(bodyParser.urlencoded({
extended: false,
}));
app.use(bodyParser.json());
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use('/', Express.static('UI'));
routes(app);
// declare 404 route
app.all('*', (req, res) => res.status(404).json({
statusCode: 404,
message: 'The URL you are trying to access does not exist. Please enter a valid url',
}));
// listen to app port
app.listen(port, () => console.log(`App listening on port ${port}`));
export default app;