forked from TrackerControl/tracker-control-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
54 lines (45 loc) · 1.42 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
50
51
52
53
54
// load express server
const express = require('express');
const app = express();
// load helpers
const path = require('path');
const helmet = require('helmet')
const bodyParser = require('body-parser');
const rateLimit = require('express-rate-limit')
require('dotenv').config();
// improve express security
app.use(helmet({
contentSecurityPolicy: {
directives: {
...helmet.contentSecurityPolicy.getDefaultDirectives(),
"img-src": ["'self'", "*.mzstatic.com"],
},
},
crossOriginEmbedderPolicy: false
}))
app.disable('x-powered-by')
const os = require('os');
if(os.hostname().indexOf("local") <= -1) { // only on remote host
const limiter = rateLimit({
windowMs: 10 * 60 * 1000, // 10 minutes
max: 100, // Limit each IP to 100 requests per `window`
standardHeaders: false,
legacyHeaders: false,
})
app.use(limiter)
}
// use pug as templates engine
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
// set up parsing of form inputs and of application/json
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// serve static files
app.use(express.static('public'));
app.use('/static', express.static('static'))
// serve favicon
app.use('/favicon.ico', express.static('favicon.ico'));
// load routes from /routes/index.js
const routes = require('./routes/index');
app.use('/', routes);
module.exports = app; // make accessible to /start.js