Skip to content

Commit

Permalink
bumb v 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hengkiardo committed May 29, 2014
1 parent cba7725 commit 353dcdb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
10 changes: 8 additions & 2 deletions README.md
Expand Up @@ -21,12 +21,18 @@ var express_enforces_ssl = require('express-enforces-ssl');

var app = express();

// use HTTPS(true) in case you are behind a load balancer (e.g. Heroku)
app.use(express_enforces_ssl.HTTPS());
app.enable('trust proxy');

app.use(express_enforces_ssl());

/*
Routes Here
*/

http.createServer(app).listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});

```

LICENCE
Expand Down
39 changes: 19 additions & 20 deletions index.js
@@ -1,28 +1,27 @@
"use strict";

var enforceHTTPS = function(force_hard) {
return function(req, res, next) {
(function(module) {
'use strict';

if(force_hard) {
redirectUrl(req, res);
}
module.exports = function enforceHTTPS() {

var isHttps = req.secure;
return function(req, res, next) {

if(isHttps){
next();
} else {
redirectUrl(req);
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);
} else {
res.send(403, "Please use HTTPS when submitting data to this server.");
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.");
}
}
}

exports.HTTPS = enforceHTTPS;
})(module);
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "express-enforces-ssl",
"version": "0.6.0",
"version": "1.0.0",
"description": "Enforces SSL for node.js express projects",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 353dcdb

Please sign in to comment.