-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
30 lines (26 loc) · 1.03 KB
/
app.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
const app = require('express')();
const path = require('path');
const enforce = require('express-sslify');
const helmet = require('helmet');
const { removeHeaders } = require('./middleware/headers');
const indexRoute = require('./routes/indexRoute');
const videosRoute = require('./routes/videosRoute');
const apiRoute = require('./routes/apiRoute');
// Force https if in production
if (process.env.NODE_ENV === 'production') {
app.use(enforce.HTTPS({ trustProtoHeader: true }));
}
// Set up security with helmet
app.use(helmet());
// Set up public directory
app.use(require('express').static(path.resolve(__dirname, 'public')));
// Remove sensitive headers
app.use(removeHeaders);
// Set up endpoints
app.use('/', indexRoute);
app.get('/heartbeat', (req, res) => res.json({ error: false, message: "I'm still standing, Yeah! Yeah! Yeah!" }));
app.use('/videos', videosRoute);
app.use('/api', apiRoute);
// The 'magic' endpoint
app.get('/magic', (req, res) => res.sendFile(path.resolve(__dirname, 'views', 'magic.html')));
module.exports = { app };