Skip to content
This repository has been archived by the owner on Aug 17, 2021. It is now read-only.

Commit

Permalink
Add express-http-to-https
Browse files Browse the repository at this point in the history
  • Loading branch information
ConorBobbleHat committed Sep 14, 2019
1 parent b809120 commit d362ce4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 55 deletions.
16 changes: 6 additions & 10 deletions Website/app.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Dependencies
const compression = require('compression')
const compression = require('compression');
const redirectToHTTPS = require('express-http-to-https').redirectToHTTPS;
const fs = require('fs');
const http = require('http');
const https = require('https');
const express = require('express');
var content = require("./content");
const app = express();

app.use(compression())
app.use(redirectToHTTPS());
app.use(compression());

// Certificate
const privateKey = fs.readFileSync('/etc/letsencrypt/live/www.bepaysmart.org/privkey.pem', 'utf8');
Expand All @@ -32,16 +34,10 @@ app.get("/pagesJSON", function(req, res) {

app.use(express.static("static"));

// Starting both http & https servers
//const httpServer = http.createServer(app);
const httpServer = express.createServer();
// Starting both http & https server
const httpServer = http.createServer(app);
const httpsServer = https.createServer(credentials, app);

// redirect everything coming in on port 80 (http) to port 443 (https)
httpServer.get("*", function (req, res){
res.redirect('https://' + req.headers.host + req.url);
});

httpServer.listen(80, () => {
console.log('HTTP Server running on port 80');
});
Expand Down
96 changes: 52 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"homepage": "https://github.com/BePaySmart/BePaySmart.org/#readme",
"dependencies": {
"express": "^4.17.1"
"express": "^4.17.1",
"express-http-to-https": "^1.1.4"
}
}

0 comments on commit d362ce4

Please sign in to comment.