Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixing error res not as param when call redirectUrl
  • Loading branch information
hengkiardo committed Jun 4, 2014
1 parent 353dcdb commit cbdd755
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
34 changes: 15 additions & 19 deletions index.js
@@ -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.");
}
}
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "express-enforces-ssl",
"version": "1.0.0",
"version": "1.1.0",
"description": "Enforces SSL for node.js express projects",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit cbdd755

Please sign in to comment.