Skip to content
Browse files

adding tests, req.url and version bump

  • Loading branch information...
1 parent 8c7fc43 commit 307c38abb32054eabf2f853eb455935f213123e0 @shapeshed committed Feb 17, 2011
Showing with 29 additions and 3 deletions.
  1. +1 −1 lib/connect-force-domain.js
  2. +3 −2 package.json
  3. +25 −0 test/connect-force-domain.test.js
View
2 lib/connect-force-domain.js
@@ -9,7 +9,7 @@ module.exports = function(domain){
domain = domain || false;
return function(req, res, next){
if (domain && (req.headers.host != domain)){
- res.writeHead(301, {"Location": 'http://' + domain});
+ res.writeHead(301, {"Location": 'http://' + domain + req.url});
res.end();
}
next();
View
5 package.json
@@ -1,8 +1,9 @@
{ "name": "connect-force-domain"
, "description": "Force all visitors onto a single domain"
+, "keywords": ["no-www", "rack", "middleware", "connect"]
, "main": "./index"
-, "author": "George Ornbo"
-, "version": "0.0.1"
+, "author": "George Ornbo <george@shapeshed.com> (http://shapeshed.com)"
+, "version": "0.0.2"
, "repository" :
{ "type" : "git"
, "url" : "https://github.com/shapeshed/connect-force-domain.git"
View
25 test/connect-force-domain.test.js
@@ -0,0 +1,25 @@
+
+var connect = require('connect'),
+ force_domain = require('connect-force-domain'),
+ assert = require('assert');
+
+app = connect.createServer(force_domain('shapeshed.com'));
+
+
+module.exports = {
+ 'GET /': function(){
+ assert.response(app,
+ { url: '/' },
+ { status: 301 , headers: { 'Location': 'http://shapeshed.com/' }});
+ },
+ 'GET /foobar': function(){
+ assert.response(app,
+ { url: '/foobar' },
+ { status: 301 , headers: { 'Location': 'http://shapeshed.com/foobar' }});
+ },
+ 'GET /foobar/': function(){
+ assert.response(app,
+ { url: '/foobar/' },
+ { status: 301 , headers: { 'Location': 'http://shapeshed.com/foobar/' }});
+ }
+};

0 comments on commit 307c38a

Please sign in to comment.
Something went wrong with that request. Please try again.