-
Notifications
You must be signed in to change notification settings - Fork 22
/
server.js
36 lines (32 loc) · 1.37 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
/* eslint no-console:0 */
import express from "express";
import routers from "./server/src/routes/Routes";
import routeErrorHandler from "./server/src/routes/RouteErrorHandler";
import bodyParser from "body-parser";
import cookieParser from "cookie-parser";
import EnvironmentConfig from "./server/src/config/EnvironmentConfig";
import path from "path";
import helmet from "helmet";
import csp from "helmet-csp";
const app = express();
app.use(helmet.hidePoweredBy());
app.use(csp({ "directives": {
"scriptSrc": ["'self'", "https://connect.facebook.net", "http://connect.facebook.net", "https://api.twitter.com"],
"styleSrc": ["'self'", "'unsafe-inline'"]
} }));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ "extended": true }));
app.use(cookieParser());
app.use(helmet.xssFilter());
const ninetyDaysInMilliseconds = 7776000000;
app.use(helmet.hsts({ "maxAge": ninetyDaysInMilliseconds, "force": true }));
app.use(helmet.referrerPolicy({ "policy": "same-origin" }));
routers(app);
const DEFAULT_PORT = 5000;
const port = EnvironmentConfig.instance(EnvironmentConfig.files.APPLICATION).get("serverPort") || DEFAULT_PORT;
const clientPath = app.get("env") === "debug" ? "/dist/" : "/";
app.use(express.static(path.join(__dirname, `${clientPath}client`)));
routeErrorHandler(app);
const server = app.listen(port);
export default server;
console.log("listening on port " + port);