-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
54 lines (50 loc) · 1.31 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
var express = require("express");
var app = express();
var path = require("path");
// If an incoming request uses
// a protocol other than HTTPS,
// redirect that request to the
// same url but with HTTPS
/*
app.get('*', function(req, res, next) {
if (req.headers['x-forwarded-proto'] !== 'https' && process.env.NODE_ENV === 'production') {
res.redirect('https://' + req.hostname + req.url);
} else {
next();
}
});
*/
/*
app.get('*', function(req, res, next) {
if (req.headers['x-forwarded-proto'] !== 'https') {
res.redirect('https://' + req.hostname + req.url);
} else {
next();
}
});
*/
app.get("*", function (req, res, next) {
if (
req.headers["x-forwarded-proto"] !== "https" &&
process.env.NODE_ENV === "production"
) {
res.redirect("https://" + req.hostname + req.url);
} else {
next();
}
});
app.use(express.static(__dirname + "/dist"));
// For all GET requests, send back index.html
// so that PathLocationStrategy can be used
// use this when you turn off the hash in angular, aka domain/#/endpoint
app.get("*", function (req, res) {
if (
req.headers["x-forwarded-proto"] !== "https" &&
process.env.NODE_ENV === "production"
) {
res.redirect("https://" + req.hostname + req.url);
} else {
res.sendFile(path.join(__dirname + "/dist/index.html"));
}
});
app.listen(process.env.PORT || 4200);