One instance of a Plugin per request
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 6fc5e7d · Browse files · 5 files·+34 added−23 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+34 added−23 removed
- tests:+0 added−7 removed
- other:+34 added−16 removed
Provenance
- Commit
53eda82- Tree
4f2be5a- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
6fc5e7d
5 files changed+34 added−23 removed
modified:lib/express/plugins/cookie.js+4 added-4 removed
53 unmodified lines545556575859606162636461626364656667688 unmodified lines53 unmodified lines Express.server.response.cookie || {})[key] = val}
// --- Expose
process.mixin(GLOBAL, exports)
// --- Cookie
exports.Cookie = Plugin.extend({ init: function() { this.__super__.apply(arguments) process.mixin(GLOBAL, exports) }, on: { request: function(event) { if (event.request.headers.cookie) event.request.cookie = exports.parseCookie(event.request.headers.cookie)8 unmodified linesmodified:lib/express/plugins/hooks.js+20 added-4 removed
2 unmodified lines34567891011121314151617181920212223242526272829303132333435161718193637383910 unmodified lines2 unmodified lines
var before = [], after = []
/** * Add a _fn_ to be excuted before a request. * * @param {function} fn * @api public */
exports.before = function(fn) { before.push(fn)}
/** * Add a _fn_ to be excuted after a request. * * @param {function} fn * @api public */
exports.after = function(fn) { after.push(fn)}
// --- Expose
process.mixin(GLOBAL, exports)
// --- Hooks
exports.Hooks = Plugin.extend({ init: function() { this.__super__.apply(arguments) process.mixin(GLOBAL, exports) }, on: { request: function(event) { $(before).each(function(fn){ fn(event)10 unmodified linesmodified:lib/express/plugins/redirect.js+4 added-4 removed
23 unmodified lines242526272829303132333431323334353637386 unmodified lines23 unmodified lines header('location', uri) halt(302)}
// --- Expose
process.mixin(GLOBAL, exports)
// --- Redirect
exports.Redirect = Plugin.extend({ init: function() { this.__super__.apply(arguments) process.mixin(GLOBAL, exports) }, on: { request: function(event) { home = set('home') || set('basepath') ||6 unmodified linesmodified:lib/express/plugin.js+6 added-4 removed
31 unmodified lines32 */33 34 exports.trigger = function(name, data) {35 $(Express.plugins).each(function(plugin){36- plugin.trigger(new Event(name, data))36+ (new plugin.klass(plugin.options)).trigger(new Event(name, data))37 })38 }39 40 /**41- * Push an instance of _plugin_ with _options_42- * to the plugin stack.41+ * Push _plugin_ with _options_ to the plugin stack.42 *43 * @param {Plugin} plugin44 * @param {hash} options45 * @api public46 */47 48 exports.use = function(plugin, options) {50- Express.plugins.push(new plugin(options))49+ Express.plugins.push({50+ klass: plugin,51+ options: options 52+ })53 }54 55 // --- Plugin56 27 unmodified linesmodified:spec/spec.plugins.js-7 removed
13 unmodified lines14 reset()15 use(CSSColors)16 end17 18- describe 'with options provided'19- it 'should merge properties'20- use(CSSColors, { foo: 'bar' })21- $(Express.plugins).last().should.have_property 'foo', 'bar'22- end23- end24- 18 describe 'Event'19 describe '#init()'20 it 'should accept arbitrary data'21 var event = new Event('foo', { bar: 'baz' })18 unmodified lines