Created
June 22, 2010 21:27
-
-
Save bentomas/449120 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From c02c28574aa9ac7ec0b2751b94240e23860b85a4 Mon Sep 17 00:00:00 2001 | |
From: Benjamin Thomas <benjamin@benjaminthomas.org> | |
Date: Tue, 22 Jun 2010 15:27:10 -0600 | |
Subject: [PATCH] Start work on properly sandboxing modules | |
--- | |
lib/connect/index.js | 14 ++++++++------ | |
1 files changed, 8 insertions(+), 6 deletions(-) | |
diff --git a/lib/connect/index.js b/lib/connect/index.js | |
index 048de95..f780a07 100644 | |
--- a/lib/connect/index.js | |
+++ b/lib/connect/index.js | |
@@ -48,7 +48,9 @@ if (typeof Object.prototype.forEach !== 'function') { | |
function Layer(config) { | |
utils.merge(this, config); | |
- utils.merge(this, config.module); | |
+ this.handle = config.module.handle; | |
+ this.handleError = config.module.handleError; | |
+ this.setup = config.module.setup; | |
// Normalize routes | |
if (this.route[this.route.length - 1] !== '/') { | |
@@ -133,13 +135,13 @@ Server.prototype.use = function(obj){ | |
if (obj.module instanceof Server) { | |
obj.handle = obj.module.handle; | |
} | |
- | |
+ | |
var layer = new Layer(obj); | |
layer.env = this.env; | |
if (layer.setup) { | |
args.unshift(layer.env); | |
- layer.setup.apply(layer, args); | |
+ layer.setup.apply(layer.module, args); | |
} | |
this.stack.push(layer); | |
@@ -210,12 +212,12 @@ Server.prototype.handle = function(req, res, outerNext) { | |
if (err) { | |
if (layer.handleError) { | |
- layer.handleError(err, req, res, next); | |
+ layer.handleError.call(layer.module, err, req, res, next); | |
} else { | |
next(err); | |
} | |
} else { | |
- layer.handle(req, res, next); | |
+ layer.handle.call(layer.module, req, res, next); | |
} | |
} catch (e) { | |
if (e instanceof assert.AssertionError) { | |
@@ -239,4 +241,4 @@ Server.prototype.handle = function(req, res, outerNext) { | |
exports.createServer = function(middleware, env){ | |
return new Server(middleware, env); | |
-}; | |
\ No newline at end of file | |
+}; | |
-- | |
1.6.5.7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment