-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (32 loc) · 964 Bytes
/
server.js
File metadata and controls
43 lines (32 loc) · 964 Bytes
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 morgan = require('morgan');
const cors = require('cors');
const helmet = require('helmet');
const Router = require('./routes');
const Fallback = require('./app/fallback');
const Swagger = require('./swagger')
const Pong = (_, response) => response
.status(200)
.send('pong');
const port = process.env.PORT || 3003;
const app = express();
// Setup
app.use(morgan(':method :url :status :response-time ms - :res[content-length]'));
app.use(cors());
app.use(helmet());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// Set this config so we can get ip address from proxy
app.enable('trust proxy')
// Swagger docs
let {CURRENT_ENV: env} = process.env
if (env == 'dev' || env == 'qa') {
app.use('/docs', Swagger.serve, Swagger.setup);
}
// Routes
app.use('/api', Router);
// healthcheck - required for Nomad
app.get('/ping', Pong)
// Error handling
app.use(Fallback);
app.listen(port);