Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
fixing error res not as param when call redirectUrl
- Loading branch information
1 parent
353dcdb
commit cbdd755
Showing
2 changed files
with
16 additions
and
20 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,23 @@ | ||
'use strict'; | ||
|
||
(function(module) { | ||
'use strict'; | ||
module.exports = function enforceHTTPS() { | ||
|
||
module.exports = function enforceHTTPS() { | ||
return function(req, res, next) { | ||
|
||
return function(req, res, next) { | ||
var isHttps = req.secure; | ||
|
||
var isHttps = req.secure; | ||
|
||
if(isHttps){ | ||
next(); | ||
} else { | ||
redirectUrl(req); | ||
} | ||
} | ||
}; | ||
|
||
var redirectUrl = function (req, res) { | ||
if(req.method === "GET") { | ||
res.redirect(301, "https://" + req.headers.host + req.originalUrl); | ||
if(isHttps){ | ||
next(); | ||
} else { | ||
res.send(403, "Please use HTTPS when submitting data to this server."); | ||
redirectUrl(req, res); | ||
} | ||
} | ||
}; | ||
|
||
})(module); | ||
var redirectUrl = function (req, res) { | ||
if(req.method === "GET") { | ||
res.redirect(301, "https://" + req.headers.host + req.originalUrl); | ||
} else { | ||
res.send(403, "Please use HTTPS when submitting data to this server."); | ||
} | ||
} |
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