forked from sumeet-bansal/tse-onboarding-fa19
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (26 loc) · 872 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
const bodyParser = require('body-parser');
const express = require('express');
const morgan = require('morgan');
const uuid = require('uuid');
const app = require('./app');
const log = app.logger;
const server = express();
// assign each request a uuid
server.use((req, res, next) => {
req.id = uuid.v4().split('-').pop();
next();
});
// enable logging
server.use(morgan(':date[web] [IP :req[X-Forwarded-For]] :method :url :status :response-time[3]ms'));
// parse urlencoded and JSON POST data
server.use(bodyParser.urlencoded({ extended: true }));
server.use(bodyParser.json());
// route the API
server.use('/api/', app.api.router);
// register error middleware
server.use(app.error.errorHandler);
server.use(app.error.notFoundHandler);
// start the server
server.listen(app.config.port, () => {
log.info('Started server on port %d.', app.config.port);
});