Skip to content

Instantly share code, notes, and snippets.

@jordanhudgens
Created August 30, 2018 17:47
Show Gist options
  • Save jordanhudgens/b2ea4c29cd39d12d315b0b0ac6094a23 to your computer and use it in GitHub Desktop.
Save jordanhudgens/b2ea4c29cd39d12d315b0b0ac6094a23 to your computer and use it in GitHub Desktop.
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