Skip to content
Browse files

added gcf and nowww

  • Loading branch information...
1 parent c6b7d3a commit 37495d272d3d28ffbdc8a067e740b2e5cb4b9f39 @coolaj86 committed Aug 11, 2011
Showing with 80 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +6 −1 lib/index.js
  3. +37 −0 lib/lib/nowww.js
  4. +2 −1 lib/package.json
  5. +14 −0 test/app.js
  6. +20 −0 test/client.js
View
1 .gitignore
@@ -0,0 +1 @@
+node_modules
View
7 lib/index.js
@@ -2,8 +2,10 @@
"use strict";
var stack = require('./lib/stack')
+ , gcf = require('express-chromeframe')
, addSendJson = require('./lib/jason-res-json')
, corsSession = require('./lib/connect-cors-session')
+ , nowww = require('./lib/nowww')
, queryparser = require('connect-queryparser')
, xcors = require('connect-xcors')
, cors
@@ -19,11 +21,14 @@
cors = xcors();
session = corsSession();
connect.addMiddleware(
- cors
+ nowww()
, queryparser()
+ , cors
, session
+ , gcf()
);
+ // TODO push into middleware layer
cors.config.headers = cors.config.headers.concat(session.headers.slice());
module.exports = connect;
View
37 lib/lib/nowww.js
@@ -0,0 +1,37 @@
+(function () {
+ "use strict";
+
+ var regExp = /(.*\/\/)www\.(.*)/i;
+
+ function nowww(req, res, next) {
+ var match
+ , url;
+
+ if (!(match = regExp.exec(req.url))) {
+ return next();
+ }
+
+ url = match[1] + match[2];
+ hostname = match[2];
+ res.statusCode = 302;
+ res.setHeader('Location', url);
+ // TODO set token to notify browser to notify user about www
+ res.write(
+ 'Quit with the www already!!! It\'s not 1990 anymore!'
+ + '<br/>'
+ + '<a href="' + url + '">' + hostname + '</a>'
+ + '<br/>NOT www.' + hostname
+ + '<br/>NOT http://' + hostname
+ + '<br/>just <a href="http://' + hostname + '">' + hostname + '</a> !!!'
+ + '<br/>'
+ + ';-P'
+ );
+ res.end();
+ }
+
+ function create() {
+ return nowww;
+ }
+
+ module.exports = create;
+}());
View
3 lib/package.json
@@ -2,7 +2,7 @@
"author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.info)",
"name": "jason",
"description": "A JSON CORS/XHR2 application platform",
- "version": "0.1.1",
+ "version": "0.1.2",
"repository": {
"type": "git",
"url": "git://github.com/coolaj86/jason.git"
@@ -14,6 +14,7 @@
"dependencies": {
"connect-queryparser": ">= 0.5.0"
, "connect-xcors": ">= 0.0.0"
+ , "express-chromeframe": ">= 0.1.1"
},
"devDependencies": {}
}
View
14 test/app.js
@@ -0,0 +1,14 @@
+(function () {
+ "use strict";
+
+ var connect = require('../lib/index');
+
+ connect.createServer(
+ connect.static(__dirname + '/public')
+ , function (req, res, next) {
+ console.log("I'll handle it from here, friend!");
+ res.json({ hello: 'friend' });
+ }
+ ).listen("5080");
+ console.log('listening on port ' + 5080);
+}());
View
20 test/client.js
@@ -0,0 +1,20 @@
+(function () {
+ "use strict";
+
+ $.ajax({
+ url: "http://localhost:5080/four-oh-four"
+ , success: function (data) {
+ console.log('Success', data);
+ }
+ , error: function (err) {
+ console.log('Error', err);
+ }
+ , complete: function (xhr) {
+ consolel.log('Complete', xhr);
+ }
+ , headers: {
+ "X-User-Session": "badSession"
+ }
+ });
+
+}());

0 comments on commit 37495d2

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