forked from zepcp/trackovid19-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
49 lines (34 loc) · 1.26 KB
/
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
47
48
49
const dotenv = require('dotenv');
const express = require('express');
const helmet = require('helmet');
const morgan = require('morgan');
const session = require('express-session');
const { json } = require('body-parser');
dotenv.config();
const logger = require('./utils/logger');
const { apiErrorHandler, resourceNotFoundHandler, isAuthenticated } = require('./utils/express-middleware');
const api = require('./api');
const auth = require('./auth');
const app = express();
app.use(session({
secret: process.env.APP_SESSION_SALT,
proxy: true,
resave: true,
saveUninitialized: true
}));
auth(app);
// Add some basic security
app.use(helmet());
app.use(json());
// Initialize the REST API logger
app.use(morgan('short', { stream: logger('trackovid-api').restAPILogger }));
app.use('/api/', isAuthenticated, api);
// Handles with the 404 Not Found
app.use(resourceNotFoundHandler);
// Handles API Error and send a specific error code for the API Rest Consumer instead of the
// stack trace message. Those kind of information should propagated to the logger.
app.use(apiErrorHandler);
const port = process.env.APP_SERVER_PORT || 3000; // set our port
// Start the server
app.listen(port);
logger('server').info(`trackovid-19 server started on port ${port}`);