-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
27 lines (21 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
//Install express server
const express = require('express');
const path = require('path');
const app = express();
// redirect to https if http
app.use((req, res, next) => {
if(req.header("x-forwarded-proto") !== "https") {
console.log("Received protocol: " + req.header("x-forwarded-proto"));
console.log("Redirecting to: https://" + req.header("host"));
res.redirect(`https://${req.header('host')}`)
} else {
next()
}
})
// Serve only the static files form the dist directory
app.use(express.static(__dirname + '/dist/personalWebsite'));
app.get('/*', function(req,res) {
res.sendFile(path.join(__dirname+'/dist/personalWebsite/index.html'));
});
// Start the app by listening on the default Heroku port
app.listen(process.env.PORT || 8080);