Comparar commits
37 Commits
| Autor | SHA1 | Data | |
|---|---|---|---|
| 45ef08cf99 | |||
| baa7d12ed6 | |||
| 822de581b3 | |||
| 3863a76fc8 | |||
| 9727fac291 | |||
| 5cadbcbbd7 | |||
| 8ee0294672 | |||
| 99789c3182 | |||
| 406a7f4fc7 | |||
| 5a11f82e0e | |||
| 33eca37ec9 | |||
| fbd9cdd11e | |||
| 6ec6657512 | |||
| 1879648be7 | |||
| 490770171d | |||
| 621063cc18 | |||
| 821defc11b | |||
| dbc1709e0e | |||
| 4d1bda0601 | |||
| 1a9a3674c2 | |||
| 99b7e74422 | |||
| add0a43c40 | |||
| 3dc7c6a254 | |||
| e645123fbd | |||
| 4b104db212 | |||
| 7cdbca0dc9 | |||
| 7d5f06b048 | |||
| e823e31550 | |||
| 34de3ede95 | |||
| 35c7317004 | |||
| 2a89f375f4 | |||
| 8d06b6752a | |||
| dba453345a | |||
| 1f76d5c7d6 | |||
| 8309537527 | |||
| d0f14f8488 | |||
| cee857af9a |
@@ -1,4 +1,24 @@
|
||||
|
||||
0.3.0 / 2010-02-11
|
||||
==================
|
||||
|
||||
* Updated haml / sass submodules. Closes #200
|
||||
* Added flash message support. Closes #64
|
||||
* Added accepts() now allows multiple args. fixes #117
|
||||
* Added support for plugins to halt. Closes #189
|
||||
* Added alternate layout support. Closes #119
|
||||
* Removed Route#run(). Closes #188
|
||||
* Fixed broken specs due to use(Cookie) missing
|
||||
|
||||
0.2.1 / 2010-02-05
|
||||
==================
|
||||
|
||||
* Added "plot" format option for Profiler (for gnuplot processing)
|
||||
* Added request number to Profiler plugin
|
||||
* Fixed binary encoding for multi-part file uploads, was previously defaulting to UTF8
|
||||
* Fixed issue with routes not firing when not files are present. Closes #184
|
||||
* Fixed process.Promise -> events.Promise
|
||||
|
||||
0.2.0 / 2010-02-03
|
||||
==================
|
||||
|
||||
|
||||
+1
-1
@@ -115,9 +115,9 @@ Express is currently being developed with node --version:
|
||||
## Contributors
|
||||
|
||||
* TJ Holowaychuk (visionmedia) <tj@vision-media.ca>
|
||||
* Aaron Heckmann (aheckmann) <aaron.heckmann+github@gmail.com>
|
||||
* Ciaran Jessup (ciaranj) <ciaranj@gmail.com>
|
||||
* Gareth Jones (csausdev) <gareth.jones@sensis.com.au>
|
||||
* Aaron Heckmann (aheckmann) <aaron.heckmann+github@gmail.com>
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
var path = require('path')
|
||||
require.paths.unshift(__dirname + '/support/js-oo/lib')
|
||||
require.paths.unshift(__dirname + '/support/ejs/lib')
|
||||
require.paths.unshift(__dirname + '/support/haml/lib')
|
||||
|
||||
+7
-17
@@ -14,6 +14,7 @@ process.mixin(require('express/dsl'))
|
||||
*/
|
||||
|
||||
var multipart = require('multipart'),
|
||||
events = require('events'),
|
||||
File = require('file').File,
|
||||
utils = require('express/utils')
|
||||
|
||||
@@ -43,19 +44,6 @@ Route = Class({
|
||||
this.fn = fn
|
||||
},
|
||||
|
||||
/**
|
||||
* Execute this route's #fn with _args_,
|
||||
* against _context_ or GLOBAL.
|
||||
*
|
||||
* @param {array} args
|
||||
* @return {mixed}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
run: function(args, context) {
|
||||
return this.fn.apply(context || GLOBAL, args)
|
||||
},
|
||||
|
||||
/**
|
||||
* Normalize _path_. When a RegExp it is simply returned,
|
||||
* otherwise a string is converted to a regular expression
|
||||
@@ -121,7 +109,7 @@ Router = Class({
|
||||
route: function(){
|
||||
var route = this.matchingRoute()
|
||||
if (route)
|
||||
return route.run(this.request.captures.slice(1), this.request)
|
||||
return route.fn.apply(this.request, this.request.captures.slice(1))
|
||||
else if (this.request.accepts('html') && set('helpful 404'))
|
||||
this.request.halt(404, require('express/pages/not-found').render(this.request))
|
||||
else
|
||||
@@ -223,13 +211,13 @@ Server = Class({
|
||||
if (request.headers['content-type'] &&
|
||||
request.headers['content-type'].indexOf('multipart/form-data') !== -1) {
|
||||
var stream = new multipart.Stream(request),
|
||||
promise = new process.Promise,
|
||||
promise = new events.Promise,
|
||||
pendingFiles = 0
|
||||
request.params = { post: {}}
|
||||
promise.timeout(set('upload timeout') || 5000)
|
||||
stream.addListener('part', function(part){
|
||||
if (part.filename) {
|
||||
var file = new File(part.tempfile = '/tmp/express-' + Number(new Date) + utils.uid(), 'w')
|
||||
var file = new File(part.tempfile = '/tmp/express-' + Number(new Date) + utils.uid(), 'w', { encoding: 'binary' })
|
||||
++pendingFiles
|
||||
part.pos = 0
|
||||
part.addListener('body', function(chunk){
|
||||
@@ -257,6 +245,7 @@ Server = Class({
|
||||
utils.mergeParam(part.name, part.buf, request.params.post)
|
||||
})
|
||||
}).addListener('complete', function(){
|
||||
if (!pendingFiles) promise.emitSuccess()
|
||||
promise.addCallback(function(){ self.route(request, response) })
|
||||
})
|
||||
}
|
||||
@@ -280,6 +269,7 @@ Server = Class({
|
||||
route: function(request, response){
|
||||
request = new Request(request, response)
|
||||
request.trigger('request')
|
||||
if (request.response.finished) return
|
||||
try {
|
||||
if (typeof (body = (new Router(request)).route()) == 'string')
|
||||
request.halt(200, body)
|
||||
@@ -300,7 +290,7 @@ Server = Class({
|
||||
// --- Express
|
||||
|
||||
Express = {
|
||||
version: '0.2.0',
|
||||
version: '0.3.0',
|
||||
config: [],
|
||||
routes: [],
|
||||
plugins: [],
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Express - Plugins - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
|
||||
|
||||
process.mixin(require('express/plugins/hooks'))
|
||||
process.mixin(require('express/plugins/flash'))
|
||||
process.mixin(require('express/plugins/cache'))
|
||||
process.mixin(require('express/plugins/cookie'))
|
||||
process.mixin(require('express/plugins/session'))
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
|
||||
// Express - Flash - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
|
||||
|
||||
exports.Flash = Plugin.extend({
|
||||
extend: {
|
||||
|
||||
/**
|
||||
* Initialize extensions.
|
||||
*/
|
||||
|
||||
init: function(){
|
||||
Request.include({
|
||||
|
||||
/**
|
||||
* Get / set flash _key_ and _val_.
|
||||
*
|
||||
* When a flash _key_ and _val_ are present,
|
||||
* it will persist in the session until outputted.
|
||||
* The _val_ pushed is returned.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* this.flash('info', 'email sent')
|
||||
* this.flash('info', 'email received')
|
||||
* this.flash('info')
|
||||
* // => ['email sent', 'email received']
|
||||
*
|
||||
* this.flash('info')
|
||||
* // => null
|
||||
*
|
||||
* @param {string} key
|
||||
* @param {string} val
|
||||
* @return {string}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
flash: function(key, val) {
|
||||
if (!this.session.flash) this.session.flash = {}
|
||||
if (!(key in this.session.flash)) this.session.flash[key] = []
|
||||
if (val)
|
||||
return this.session.flash[key].push(val), val
|
||||
else if (key) {
|
||||
var vals = this.session.flash[key]
|
||||
delete this.session.flash[key]
|
||||
if (vals.length) return vals
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1,8 +1,7 @@
|
||||
|
||||
// Express - Hooks - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
|
||||
|
||||
var before = [],
|
||||
after = []
|
||||
exports.callbacks = { before: [], after: [] }
|
||||
|
||||
/**
|
||||
* Add a _fn_ to be excuted before a request.
|
||||
@@ -12,7 +11,7 @@ var before = [],
|
||||
*/
|
||||
|
||||
exports.before = function(fn) {
|
||||
before.push(fn)
|
||||
exports.callbacks.before.push(fn)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,7 +22,7 @@ exports.before = function(fn) {
|
||||
*/
|
||||
|
||||
exports.after = function(fn) {
|
||||
after.push(fn)
|
||||
exports.callbacks.after.push(fn)
|
||||
}
|
||||
|
||||
// --- Hooks
|
||||
@@ -36,7 +35,8 @@ exports.Hooks = Plugin.extend({
|
||||
*/
|
||||
|
||||
init: function() {
|
||||
process.mixin(GLOBAL, exports)
|
||||
process.mixin(GLOBAL, { before: exports.before,
|
||||
after: exports.after })
|
||||
}
|
||||
},
|
||||
|
||||
@@ -49,7 +49,7 @@ exports.Hooks = Plugin.extend({
|
||||
*/
|
||||
|
||||
request: function(event) {
|
||||
$(before).each(function(fn){
|
||||
$(exports.callbacks.before).each(function(fn){
|
||||
fn.call(event.request, event.request)
|
||||
})
|
||||
},
|
||||
@@ -59,7 +59,7 @@ exports.Hooks = Plugin.extend({
|
||||
*/
|
||||
|
||||
response: function(event) {
|
||||
$(after).each(function(fn){
|
||||
$(exports.callbacks.after).each(function(fn){
|
||||
fn.call(event.request, event.request)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,7 +1,29 @@
|
||||
|
||||
// Express - Profiler - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
|
||||
|
||||
var n = 0
|
||||
|
||||
exports.Profiler = Plugin.extend({
|
||||
extend: {
|
||||
|
||||
/**
|
||||
* Initialize profiler options.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - format 'plot' outputs request duration in milliseconds only
|
||||
*
|
||||
* @param {hash} options
|
||||
* @api private
|
||||
*/
|
||||
|
||||
init: function(options) {
|
||||
process.mixin(this, options)
|
||||
}
|
||||
},
|
||||
|
||||
// --- Events
|
||||
|
||||
on: {
|
||||
|
||||
/**
|
||||
@@ -17,9 +39,13 @@ exports.Profiler = Plugin.extend({
|
||||
*/
|
||||
|
||||
response: function(event) {
|
||||
puts(event.request.method + ' ' +
|
||||
event.request.url.pathname + ': ' +
|
||||
(Number(new Date) - this.start) + ' ms')
|
||||
if (exports.Profiler.format === 'plot')
|
||||
puts(Number(new Date) - this.start)
|
||||
else
|
||||
puts(event.request.method + ' ' +
|
||||
event.request.url.pathname + ': ' +
|
||||
(Number(new Date) - this.start) + ' ms' +
|
||||
' #' + ++n)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -138,7 +138,7 @@ exports.Store.Memory = exports.Store.extend({
|
||||
}
|
||||
})
|
||||
|
||||
// --- Cache
|
||||
// --- Session
|
||||
|
||||
exports.Session = Plugin.extend({
|
||||
extend: {
|
||||
|
||||
@@ -51,7 +51,7 @@ exports.View = Plugin.extend({
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - layout: Whether or not to use a layout. Defaults to true
|
||||
* - layout: The layout to use, none when falsey. Defaults to 'layout'
|
||||
* - context: Most engines support an evaluation context (the 'this' keyword)
|
||||
* - locals: Most engines support a hash of local variable names / values.
|
||||
*
|
||||
@@ -67,12 +67,12 @@ exports.View = Plugin.extend({
|
||||
path = set('views') + '/' + view,
|
||||
type = path.split('.').slice(-2)[0],
|
||||
ext = utils.extname(path),
|
||||
layout = options.layout === undefined ? true : options.layout
|
||||
layout = options.layout === undefined ? 'layout' : options.layout
|
||||
self.contentType(ext)
|
||||
function render(content) {
|
||||
content = engine[type].render(content, options)
|
||||
if (layout)
|
||||
self.render('layout.' + type + '.' + ext, process.mixin(true, options, {
|
||||
self.render(layout + '.' + type + '.' + ext, process.mixin(true, options, {
|
||||
layout: false,
|
||||
locals: {
|
||||
body: content
|
||||
|
||||
@@ -113,19 +113,31 @@ exports.Request = Class({
|
||||
|
||||
/**
|
||||
* Check if Accept header includes the mime type
|
||||
* for the given _path_, which calls mime.type().
|
||||
* for any of the given paths, which calls mime.type().
|
||||
*
|
||||
* When no Accept header is present true will be
|
||||
* returned as stated in the HTTP specification.
|
||||
*
|
||||
* @param {string} path
|
||||
* Example:
|
||||
*
|
||||
* this.accepts('png')
|
||||
* this.accepts('png', 'jpg', 'gif')
|
||||
* this.accepts('image.png')
|
||||
* this.accepts('path/to/image.png')
|
||||
*
|
||||
* @param {mixed} ...
|
||||
* @return {bool}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
accepts: function(path) {
|
||||
return this.header('accept') ?
|
||||
this.header('accept').indexOf(mime.type(path)) !== -1 :
|
||||
accepts: function() {
|
||||
var accept = this.header('accept')
|
||||
return accept ?
|
||||
$(arguments).any(function(path){
|
||||
var type = mime.type(path)
|
||||
return accept.indexOf(type) !== -1 ||
|
||||
accept.indexOf(type.split('/')[0]+'/*') !== -1
|
||||
}) :
|
||||
true
|
||||
},
|
||||
|
||||
|
||||
+1
-1
Submodule lib/support/haml updated: b1fa42226b...8ba80770ef
+1
-1
Submodule lib/support/sass updated: dfc1cd027f...0dd500e7cd
@@ -43,6 +43,7 @@ specs = {
|
||||
'plugins.hooks',
|
||||
'plugins.cookie',
|
||||
'plugins.session',
|
||||
'plugins.flash',
|
||||
],
|
||||
dependant: [
|
||||
'element-collection'
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
|
||||
describe 'Express'
|
||||
before_each
|
||||
reset()
|
||||
use(require('express/plugins/cookie').Cookie)
|
||||
use(require('express/plugins/session').Session)
|
||||
use(require('express/plugins/flash').Flash)
|
||||
Session.store.clear()
|
||||
end
|
||||
|
||||
describe 'Flash'
|
||||
describe 'flash()'
|
||||
it 'should push a flash message'
|
||||
var headers = { headers: { cookie: 'sid=123' }}
|
||||
post('/', function(){ return this.flash('info', 'email sent') })
|
||||
get('/', function(){ return this.flash('info', 'email received') })
|
||||
get('/info', function(){ return this.flash('info').join(', ') })
|
||||
get('/messages', function(){ return this.flash('info') || 'empty' })
|
||||
|
||||
post('/', headers).body.should.eql 'email sent'
|
||||
get('/', headers).body.should.eql 'email received'
|
||||
get('/info', headers).body.should.eql 'email sent, email received'
|
||||
get('/messages').body.should.eql 'empty'
|
||||
// TODO: seperate once segfault is fixed...
|
||||
end
|
||||
|
||||
it 'should return the message pushed'
|
||||
get('/', function(){ return this.flash('info', 'email sent') })
|
||||
get('/').body.should.eql 'email sent'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,7 +2,10 @@
|
||||
describe 'Express'
|
||||
before_each
|
||||
reset()
|
||||
use(require('express/plugins/hooks').Hooks)
|
||||
hooks = require('express/plugins/hooks')
|
||||
use(hooks.Hooks)
|
||||
hooks.callbacks.before = []
|
||||
hooks.callbacks.after = []
|
||||
end
|
||||
|
||||
describe 'Hooks'
|
||||
@@ -17,6 +20,15 @@ describe 'Express'
|
||||
get('/user', function(){})
|
||||
get('/user').body.should.eql 'foobar'
|
||||
end
|
||||
|
||||
it 'should be able to halt the request'
|
||||
GLOBAL.before(function(){
|
||||
this.halt(404, 'woo!')
|
||||
})
|
||||
get('/user', function(){ return 'fail' })
|
||||
get('/user').status.should.eql 404
|
||||
get('/user').body.should.eql 'woo!'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'after()'
|
||||
|
||||
@@ -58,6 +58,29 @@ describe 'Express'
|
||||
get('/user', { headers: { accept: null }}).body.should.eql 'true'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'should allow multiple arguments'
|
||||
it 'should return true if any mime type is present'
|
||||
get('/user', function(){ return this.accepts('jpeg', 'png').toString() })
|
||||
get('/user', { headers: { accept: 'image/gif,image/png' }}).body.should.eql 'true'
|
||||
end
|
||||
|
||||
it 'should return false if none of the mime types are present'
|
||||
get('/user', function(){ return this.accepts('jpeg', 'png').toString() })
|
||||
get('/user', { headers: { accept: 'text/plain,text/html' }}).body.should.eql 'false'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when a media type range was sent'
|
||||
it 'should return true if the group media type matches'
|
||||
get('/user', function(){ return this.accepts('html').toString() })
|
||||
get('/user', { headers: { accept: 'text/plain,text/*' }}).body.should.eql 'true'
|
||||
end
|
||||
it 'should return false if the group media type does not match'
|
||||
get('/user', function(){ return this.accepts('ogg').toString() })
|
||||
get('/user', { headers: { accept: 'text/plain,text/*' }}).body.should.eql 'false'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#halt()'
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário