Documenting plugins
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent f21c1de · Browse files · 8 files·+79 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+79 added−0 removed
- other:+79 added−0 removed
Provenance
- Commit
e7e2c4e- Tree
5bc8f83- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
f21c1de
8 files changed+79 added−0 removed
modified:lib/express/plugins/body-decoder.js+7 added
123456789101112131415166 unmodified lines
// Express - BodyDecoder - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
exports.BodyDecoder = Plugin.extend({ on: { /** * Decodes common content-types, currently handles: * * - application/x-www-form-urlencoded */ request: function(event) { var request = event.request request.uri.post = request.header('content-type') && 6 unmodified linesmodified:lib/express/plugins/common-logger.js+5 added
29 unmodified lines303132333435363738394041428 unmodified lines29 unmodified lines// --- CommonLogger exports.CommonLogger = Plugin.extend({ on: { /** * Output log data. */ response: function(event) { puts([event.request.headers.host, '-', '-',8 unmodified linesmodified:lib/express/plugins/content-length.js+5 added
12345678910111213144 unmodified lines
// Express - ContentLength - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
exports.ContentLength = Plugin.extend({ on: { /** * Assign Content-Length header unless present. */ response: function(event) { var response = event.request.response response.headers['content-length'] = response.headers['content-length'] ||4 unmodified linesmodified:lib/express/plugins/cookie.js+17 added
41 unmodified lines4243444546474849505152535424 unmodified lines7980818283848586878889909192939495969798991001011021031041052 unmodified lines41 unmodified lines// --- Cookie
exports.Cookie = Plugin.extend({ extend: { /** * Initialize extensions. */ init: function() { Request.include({
/**24 unmodified lines } }) } }, // --- Events on: { /** * Parser request cookie data. */ request: function(event) { event.request.response.cookies = [] if (event.request.headers.cookie) event.request.cookies = exports.parseCookie(event.request.headers.cookie) }, /** * Set the Set-Cookie header when response cookies are available. */ response: function(event) { if (event.response.cookies.length) event.request.header('set-cookie', event.response.cookies.join(', ')) }2 unmodified linesmodified:lib/express/plugins/hooks.js+17 added
28 unmodified lines29 // --- Hooks30 31 exports.Hooks = Plugin.extend({32 extend: {33+ 34+ /**35+ * Initialize extensions.36+ */37+ 38 init: function() {39 process.mixin(GLOBAL, exports)40 }41 },42+ 43+ // --- Events44+ 45 on: {46+ 47+ /**48+ * Invoke all before handlers.49+ */50+ 51 request: function(event) {52 $(before).each(function(fn){53 fn.call(event.request)54 })55 },56 57+ /**58+ * Invoke all after handlers.59+ */60+ 61 response: function(event) {62 $(after).each(function(fn){63 fn.call(event.request)64 })3 unmodified linesmodified:lib/express/plugins/method-override.js+5 added
12345678910111213142 unmodified lines
// Express - MethodOverride - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
exports.MethodOverride = Plugin.extend({ on: { /** * Set request method to __method__ param when present. */ request: function(event) { if (event.request.param('__method__')) event.request.method = event.request.param('__method__').toLowerCase() }2 unmodified linesmodified:lib/express/plugins/profiler.js+9 added
1 unmodified line2 // Express - Profiler - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3 4 exports.Profiler = Plugin.extend({5 on: {6+ 7+ /**8+ * Start timer.9+ */10+ 11 request: function(event) {12 this.start = Number(new Date)13 },14 15+ /**16+ * Output duration.17+ */18+ 19 response: function(event) {20 puts(event.request.method + ' ' + 21 event.request.uri.path + ': ' + 22 (Number(new Date) - this.start) + ' ms')3 unmodified linesmodified:lib/express/plugins/redirect.js+14 added
1 unmodified line2 // Express - Redirect - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3 4 exports.Redirect = Plugin.extend({5 extend: {6+ 7+ /**8+ * Initialize extensions.9+ */10+ 11 init: function() {12 Request.include({13 14 /**23 unmodified lines38 } 39 })40 }41 },42+ 43+ // --- Events44+ 45 on: {46+ 47+ /**48+ * Assign home to 'home', 'basepath' or '/'.49+ * Assign back to 'referrer' or 'referer' headers.50+ */51+ 52 request: function(event) {53 event.request.home = set('home') || set('basepath') || '/'54 event.request.back = event.request.header('referrer') || event.request.header('referer')55 }2 unmodified lines