Skip to content

Commit

Permalink
Merge branch 'refactor-redirect-middleware'
Browse files Browse the repository at this point in the history
  • Loading branch information
shanebo committed Dec 7, 2015
2 parents fb86e6d + dafd174 commit da525d1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions lib/middleware/redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ Redirects.prototype = {
},

handler: function(request, response, next){
// update this to use request.hostname, request.protocol
var protocol = request.connection.encrypted ? 'https://' : 'http://';
var host = request.headers.host ? request.headers.host.split(':')[0] : false;
var url = request.url.toLowerCase();
var domain = request.protocol + '//' + request.hostname;

if (this.redirects[url]) {
response.redirect(this.redirects[url], 301);
} else if (!host) {
} else if (!request.hostname) {
next();
} else if (this.redirects[protocol + host]) {
response.redirect(this.redirects[protocol + host] + url, 301);
} else if (this.redirects[domain]) {
response.redirect(this.redirects[domain] + url, 301);
} else {
next();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "calvin",
"version": "0.9.13",
"version": "0.9.14",
"description": "A tiny server, router, and middleware framework.",
"keywords": ["framework"],
"repository": "git://github.com/shanebo/calvin.git",
Expand Down

0 comments on commit da525d1

Please sign in to comment.