Created
August 30, 2018 17:47
-
-
Save jordanhudgens/b2ea4c29cd39d12d315b0b0ac6094a23 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const port = process.env.PORT || 8080; | |
const app = express(); | |
app.enable("trust proxy"); | |
app.use(function(req, res, next) { | |
console.log("inside app use"); | |
if (req.protocol !== "https") { | |
console.log("inside conditional"); | |
var secureUrl = "https://" + req.headers["host"] + req.url; | |
res.writeHead(301, { Location: secureUrl }); | |
res.end(); | |
} | |
next(); | |
}); | |
app.use(express.static(__dirname + "/dist/")); | |
app.get(/.*/, function(req, res) { | |
console.log("inside get"); | |
res.sendFile(__dirname + "/dist/index.html"); | |
}); | |
app.listen(port); | |
console.log("server started"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment