Permalink
Browse files

SSL support

  • Loading branch information...
rauchg committed Mar 15, 2011
1 parent ef4d5c4 commit f37e8fac064755a321c803be725af8a388369b0c
Showing with 49 additions and 45 deletions.
  1. +49 −45 index.js
View
@@ -11,61 +11,65 @@
var express = require('express')
, join = require('path').join
- , Server = express.Server
- ? express.Server
- : express.HTTPServer;
+ , servers = express.Server
+ ? [express.Server]
+ : [express.HTTPServer, express.HTTPSServer];
-/**
- * Namespace using the given `path`, providing a callback `fn()`,
- * which will be invoked immediately, resetting the namespace to the previous.
- *
- * @param {String} path
- * @param {Function} fn
- * @return {Server} for chaining
- * @api public
- */
+servers.forEach(function(Server){
-Server.prototype.namespace = function(path, fn){
- (this._ns = this._ns || []).push(path);
- fn.call(this);
- this._ns.pop();
- return this;
-};
+ /**
+ * Namespace using the given `path`, providing a callback `fn()`,
+ * which will be invoked immediately, resetting the namespace to the previous.
+ *
+ * @param {String} path
+ * @param {Function} fn
+ * @return {Server} for chaining
+ * @api public
+ */
-/**
- * Return the current namespace.
- *
- * @return {String}
- * @api public
- */
+ Server.prototype.namespace = function(path, fn){
+ (this._ns = this._ns || []).push(path);
+ fn.call(this);
+ this._ns.pop();
+ return this;
+ };
-Server.prototype.__defineGetter__('currentNamespace', function(){
- return join.apply(this, this._ns).replace(/\/$/, '') || '/';
-});
+ /**
+ * Return the current namespace.
+ *
+ * @return {String}
+ * @api public
+ */
-/**
- * Proxy HTTP methods to provide namespacing support.
- */
+ Server.prototype.__defineGetter__('currentNamespace', function(){
+ return join.apply(this, this._ns).replace(/\/$/, '') || '/';
+ });
+
+ /**
+ * Proxy HTTP methods to provide namespacing support.
+ */
-express.router.methods.concat(['del', 'all']).forEach(function(method){
- var orig = Server.prototype[method];
- Server.prototype[method] = function(){
- var args = Array.prototype.slice.call(arguments)
- , path = args.shift()
- , fn = args.pop()
- , self = this;
+ express.router.methods.concat(['del', 'all']).forEach(function(method){
+ var orig = Server.prototype[method];
+ Server.prototype[method] = function(){
+ var args = Array.prototype.slice.call(arguments)
+ , path = args.shift()
+ , fn = args.pop()
+ , self = this;
+
+ this.namespace(path, function(){
+ var curr = this.currentNamespace;
+ args.forEach(function(fn){
+ fn.namespace = curr;
+ orig.call(self, curr, fn);
+ });
- this.namespace(path, function(){
- var curr = this.currentNamespace;
- args.forEach(function(fn){
fn.namespace = curr;
orig.call(self, curr, fn);
});
- fn.namespace = curr;
- orig.call(self, curr, fn);
- });
+ return this;
+ };
+ });
- return this;
- };
});

0 comments on commit f37e8fa

Please sign in to comment.