-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
33 lines (27 loc) · 796 Bytes
/
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
// server.js
const express = require('express');
const path = require('path');
const app = express();
// Run the app by serving the static files
// in the dist directory
app.use(express.static(__dirname + '/dist'));
const forceSSL = function() {
return function (req, res, next) {
if (req.headers['x-forwarded-proto'] !== 'https') {
return res.redirect(
['https://', req.get('Host'), req.url].join('')
);
}
next();
}
}
app.use(forceSSL());
app.get('/*', function(req, res) {
res.sendFile(path.join(__dirname + '/dist/index.html'));
});
// listen (start app with node server.js) ======================================
var port = Number(process.env.PORT || 5000);
//var port = 3000;
app.listen(port, function() {
console.log("Listening on " + port);
});