Skip to content

Commit

Permalink
Merge pull request #3 from shaunwarman/remove-www-prefix
Browse files Browse the repository at this point in the history
feat: add removeWwwPrefix flag to remove prefix from redirect url
  • Loading branch information
niftylettuce authored May 27, 2020
2 parents f44593e + 3fb1444 commit bdcc4e3
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ProxyServer {
name: process.env.CERTBOT_WELL_KNOWN_NAME || null,
contents: process.env.CERTBOT_WELL_KNOWN_CONTENTS || null
},
removeWwwPrefix: true,
// useful option if you don't need https redirect
// (e.g. it's just a certbot server)
redirect: true,
Expand All @@ -39,6 +40,8 @@ class ProxyServer {

if (this.config.redirect)
router.use((req, res) => {
if (this.config.removeWwwPrefix)
req.headers.host = req.headers.host.replace('www.', '');
res.writeHead(301, {
Location: parse(`https://${req.headers.host}${req.url}`).href
});
Expand Down

0 comments on commit bdcc4e3

Please sign in to comment.