Last active
October 2, 2023 04:54
-
-
Save hareeqi/dcc0d409db57668294a7f0d8970aa1e4 to your computer and use it in GitHub Desktop.
Redirect HTTP to HTTPS nodeJs (http2https.js)
This file contains 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
// Make sure to run the code using sudo as port 80 needs sudo access | |
const http = require('http'); | |
const server = http.createServer((req, res) => { | |
res.writeHead(301,{Location: `https://${req.headers.host}${req.url}`}); | |
res.end(); | |
}); | |
server.listen(80); | |
console.log(`http2https ==> 80:443`); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A more generic solution can be achieved with a simple middleware