-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (39 loc) · 994 Bytes
/
server.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
44
45
46
// Import Externals
const express = require('express');
const bodyParser = require('body-parser');
const morgan = require('morgan');
require('dotenv').config();
// Config
const PORT = process.env.PORT || 8080;
const app = express();
const routes = require('./routes');
const util = require('./utilities');
// Body Parser
app.use(
bodyParser.urlencoded({
extended: true,
}),
);
app.use(bodyParser.json());
// Morgan Logging
app.use(morgan('tiny', {
skip(req, res) {
const path = /^\/v\d+\/health$/;
return path.test(req.baseUrl);
},
}));
app.get('/', (req, res) => {
res.json({
status: 'server up',
});
});
// API Routes
app.use('/v1/accounts', routes.accounts);
app.use('/v1/events', routes.events);
app.use('/v1/health', routes.health);
app.use('/v1/organizations', routes.organizations);
app.use('/v1/sessions', routes.sessions);
app.use('/v1/tokens', routes.tokens);
const server = app.listen(PORT);
// Set signal listening for Docker
util.Signal(server);