-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
31 lines (22 loc) · 1.15 KB
/
app.js
File metadata and controls
31 lines (22 loc) · 1.15 KB
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
const express = require('express');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const swaggerUI = require('swagger-ui-express');
const YAML = require('yamljs');
const swaggerDocument = YAML.load('./api/swagger/swagger.yaml');
// You want to try from JSON directly, lazy to create json, u can try this shortcut and comment YAML part
// console.log(JSON.stringify(swaggerDocument, null, ' '));
// const swaggerDocument = require('./api/swagger/swagger.json');
let app = express();
// Configure morgan to log your requests, with a standard date & time format
morgan.token('time', (req, res) => new Date().toISOString());
app.use(morgan('[:time] :remote-addr :method :url :status :res[content-length] :response-time ms'));
// Setup bodyParsing middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Mount the APIs specific to version
app.use('/api/v1', require('./api/v1'));
// Mount the SwaggerUI middleware pipeline to host API documentation
let swaggerOptions = { explorer: false };
app.use('/api/v1/docs', swaggerUI.serve, swaggerUI.setup(swaggerDocument, swaggerOptions));
module.exports = app;