Comparar commits

..

45 Commits

Autor SHA1 Mensagem Data
visionmedia d893009a8d Release 0.7.3 2010-03-16 13:17:41 -07:00
visionmedia b62e1741be Fixed requiring of haml / sass 2010-03-16 13:16:55 -07:00
visionmedia 903c2aa642 Added package.json 2010-03-16 08:31:33 -07:00
visionmedia d0a8bb550e Release 0.7.2 2010-03-16 08:08:17 -07:00
visionmedia f96f1423e1 Fixed GIT submodules (HAH!) 2010-03-16 08:06:26 -07:00
visionmedia 7bf17f2f61 Removed old support dir 2010-03-16 08:03:57 -07:00
visionmedia 670b6cfc15 Merge branch 'remove-kiwi' 2010-03-16 08:03:33 -07:00
visionmedia b6d2c8479c Release 0.7.1 2010-03-16 08:03:06 -07:00
visionmedia 5aaa114271 Docs 2010-03-16 08:01:51 -07:00
visionmedia e99c2791bb Docs 2010-03-16 07:58:06 -07:00
visionmedia 656d7754cd Express now using submodules again until a PM is adopted 2010-03-16 07:54:20 -07:00
visionmedia 4aaf10fbfc Moved support 2010-03-16 07:39:56 -07:00
visionmedia 85e77b77aa Added submodules 2010-03-16 07:02:49 -07:00
visionmedia f23ef09247 Chat example using millisecond conversions from ext 2010-03-15 16:00:39 -07:00
visionmedia 440d956438 Refactored Session#startReaper() with ext millisecond conversions 2010-03-15 15:59:37 -07:00
visionmedia acd2852cf3 ext >= 0.2.4 2010-03-15 15:58:02 -07:00
visionmedia 4246f43bdf ext >= 0.2.3 2010-03-15 09:57:38 -07:00
visionmedia 7d33769cd2 Revert "Removed sass / haml "dependencies""
This reverts commit 31fdba80d4.
2010-03-15 09:43:29 -07:00
visionmedia 31fdba80d4 Removed sass / haml "dependencies" 2010-03-15 09:42:15 -07:00
visionmedia 77f8e460d0 Better example app 2010-03-15 09:31:11 -07:00
visionmedia 51e51db9f7 Docs 2010-03-15 09:16:13 -07:00
visionmedia 73c506f19c Release 0.7.0 2010-03-15 09:13:18 -07:00
visionmedia 79143f3334 Chat sample app using pass() 2010-03-15 09:10:50 -07:00
visionmedia 128ba9040e Refactored Router#matchingRoute() 2010-03-15 09:09:51 -07:00
visionmedia 300cfe74ad Request#pass() accepts a pathname string 2010-03-15 09:02:44 -07:00
visionmedia f008af05bd Merge branch 'pull' 2010-03-15 08:54:57 -07:00
Aaron Heckmann 3aa870d6bd return this in pass 2010-03-15 08:50:35 -07:00
Aaron Heckmann 25e1a8c001 add pass specs 2010-03-15 08:50:26 -07:00
Aaron Heckmann 0ba3b114b0 add pass support 2010-03-15 08:50:20 -07:00
visionmedia c429e88e8e Updated --version of node tested against in readme 2010-03-15 08:42:22 -07:00
Aaron Heckmann c7a2fe8440 remove profiler from plugins.js 2010-03-15 08:41:21 -07:00
Aaron Heckmann de237e760b remove Profiler 2010-03-15 08:41:03 -07:00
visionmedia 927f5c9883 Logger copyright 2010-03-12 07:36:50 -08:00
visionmedia 88f461baf2 Logger using Date#format() 2010-03-12 07:14:57 -08:00
visionmedia 3251ae26a0 Fixed plot format 2010-03-12 07:09:56 -08:00
visionmedia e84c81633e "combined" using printf() 2010-03-12 07:09:20 -08:00
visionmedia a2ec966ac7 "common" Logger format using printf() 2010-03-12 07:06:47 -08:00
visionmedia 69660fbfda Merge branch 'integration' 2010-03-12 06:58:34 -08:00
visionmedia dcedca1a80 Removed 'sinatra' logger, added duration to 'common' log format 2010-03-12 06:58:23 -08:00
visionmedia 6455e954fc Removed CommonLogger, use Logger 2010-03-12 06:53:17 -08:00
visionmedia 646904688f No need for utils.mixin() here 2010-03-11 11:16:48 -08:00
visionmedia 62779fc972 Doc typo 2010-03-11 11:14:33 -08:00
visionmedia fdee4cde26 Sample app in readme 2010-03-11 11:14:02 -08:00
visionmedia 0c18ac5adc Added kiwi installation docs 2010-03-11 11:05:41 -08:00
Aaron Heckmann 5e74723a92 add logger 2010-03-10 22:09:07 -05:00
23 arquivos alterados com 243 adições e 197 exclusões
+2
Ver Arquivo
@@ -1 +1,3 @@
.DS_Store
*.seed
*.log
+12
Ver Arquivo
@@ -0,0 +1,12 @@
[submodule "lib/support/oo"]
path = lib/support/oo
url = git://github.com/visionmedia/js-oo.git
[submodule "lib/support/ext"]
path = lib/support/ext
url = git://github.com/visionmedia/ext.js.git
[submodule "lib/support/sass"]
path = lib/support/sass
url = git://github.com/visionmedia/sass.js.git
[submodule "lib/support/haml"]
path = lib/support/haml
url = git://github.com/creationix/haml-js.git
+25
Ver Arquivo
@@ -1,4 +1,29 @@
0.7.3 / 2010-03-16
==================
* Added package.json
* Fixed requiring of haml / sass due to kiwi removal
0.7.2 / 2010-03-16
==================
* Fixed GIT submodules (HAH!)
0.7.1 / 2010-03-16
==================
* Changed; Express now using submodules again until a PM is adopted
* Changed; chat example using millisecond conversions from ext
0.7.0 / 2010-03-15
==================
* Added Request#pass() support (finds the next matching route, or the given path)
* Added Logger plugin (default "common" format replaces CommonLogger)
* Removed Profiler plugin
* Removed CommonLogger plugin
0.6.0 / 2010-03-11
==================
+18 -22
Ver Arquivo
@@ -24,14 +24,16 @@
## Installation
Currently Express must be cloned (or downloaded), you can use the following command to
get rolling and initialize the submodule dependencies:
Install the [Kiwi package manager for nodejs](http://github.com/visionmedia/kiwi)
and run:
$ kiwi -v install express
or
$ git clone git://github.com/visionmedia/express.git && cd express && git submodule update --init && make app
Or with the [gh](http://github.com/visionmedia/gh) utility:
$ gh clone visionmedia express && cd express && git submodule update --init && make app
Install via git clone:
$ git://github.com/visionmedia/express.git && cd express && git submodule update --init
## Performance
@@ -42,30 +44,24 @@ Or with the [gh](http://github.com/visionmedia/gh) utility:
## Examples
Below is a minimal app example when express is already within your load path.
Below is a tiny Express application. View the [Wiki](http://wiki.github.com/visionmedia/express/) for detailed information.
require.paths.unshift('express/lib')
require('express')
require('express/plugins')
configure(function(){
use(MethodOverride)
use(ContentLength)
set('root', __dirname)
get('/user', function(){
this.redirect('/user/' + this.currentUser.id)
})
get('/hello', function(){
this.contentType('html')
return '<h1>World<h1>'
})
get('/user/:id?', function(id) {
get('/user/:id', function(id){
this.render('user.haml.html', {
locals: {
name: id ? 'User ' + id : 'You'
user: this.currentUser,
usersOnline: Session.store.length()
}
})
})
run()
## Running Tests
@@ -84,7 +80,7 @@ Run individual suites:
...
Express is currently being developed with node --version:
v0.1.31
v0.1.32
## More Information
+6 -11
Ver Arquivo
@@ -4,25 +4,20 @@ require('express')
require('express/plugins')
var messages = [],
utils = require('express/utils'),
kiwi = require('kiwi')
utils = require('express/utils')
configure(function(){
var fiveMinutes = 300000,
oneMinute = 60000
kiwi.seed('haml')
kiwi.seed('sass')
use(MethodOverride)
use(ContentLength)
use(CommonLogger)
use(Cookie)
use(Cache, { lifetime: fiveMinutes, reapInterval: oneMinute })
use(Session, { lifetime: fiveMinutes, reapInterval: oneMinute })
use(Cache, { lifetime: (5).minutes, reapInterval: (1).minute })
use(Session, { lifetime: (15).minutes, reapInterval: (1).minute })
use(Logger)
set('root', __dirname)
})
get('/', function(){
this.redirect('/chat')
this.pass('/chat')
})
get('/chat', function(){
+1 -5
Ver Arquivo
@@ -3,17 +3,13 @@ require.paths.unshift('lib')
require('express')
require('express/plugins')
var kiwi = require('kiwi')
configure(function(){
kiwi.seed('haml')
kiwi.seed('sass')
use(MethodOverride)
use(ContentLength)
use(CommonLogger)
use(Cookie)
use(Session)
use(Flash)
use(Logger)
set('root', __dirname)
})
+5 -3
Ver Arquivo
@@ -1,5 +1,7 @@
var kiwi = require('kiwi')
kiwi.require('oo', '>= 1.2.0')
kiwi.require('ext', '>= 0.2.2')
require.paths.unshift(__dirname + '/support/ext/lib')
require.paths.unshift(__dirname + '/support/haml/lib')
require.paths.unshift(__dirname + '/support/sass/lib')
require('ext')
require('support/oo/lib/oo')
require('express/core')
+21 -9
Ver Arquivo
@@ -104,10 +104,19 @@ Router = Class({
* @api private
*/
route: function(){
var route = this.matchingRoute()
if (route)
return route.fn.apply(this.request, this.request.captures.slice(1))
route: function() {
var body,
route = this.matchingRoute()
if (route) {
body = route.fn.apply(this.request, this.request.captures.slice(1));
if (this.request.passed) {
if (typeof this.request.passed === 'string')
this.request.url.pathname = this.request.passed
this.request.passed = false
return this.route()
}
return body
}
else if (this.request.accepts('html') && set('helpful 404'))
this.request.halt(404, require('express/pages/not-found').render(this.request))
else
@@ -121,10 +130,13 @@ Router = Class({
* @api private
*/
matchingRoute: function(){
return Express.routes.find(function(route){
return this.match(route)
}, this)
matchingRoute: function() {
this.lastMatchingRoute = this.lastMatchingRoute || 0
var routes = Express.routes, route
while (route = routes[this.lastMatchingRoute++])
if (this.match(route))
break
return route
},
/**
@@ -302,7 +314,7 @@ Server = Class({
// --- Express
Express = {
version: '0.6.0',
version: '0.7.3',
config: [],
routes: [],
plugins: [],
+8 -10
Ver Arquivo
@@ -1,13 +1,11 @@
// Express - Plugins - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
var utils = require('express/utils')
utils.mixin(require('express/plugins/hooks'))
utils.mixin(require('express/plugins/flash'))
utils.mixin(require('express/plugins/cache'))
utils.mixin(require('express/plugins/cookie'))
utils.mixin(require('express/plugins/session'))
utils.mixin(require('express/plugins/profiler'))
utils.mixin(require('express/plugins/common-logger'))
utils.mixin(require('express/plugins/content-length'))
utils.mixin(require('express/plugins/method-override'))
global.merge(require('express/plugins/hooks'))
global.merge(require('express/plugins/flash'))
global.merge(require('express/plugins/cache'))
global.merge(require('express/plugins/cookie'))
global.merge(require('express/plugins/session'))
global.merge(require('express/plugins/logger'))
global.merge(require('express/plugins/content-length'))
global.merge(require('express/plugins/method-override'))
-50
Ver Arquivo
@@ -1,50 +0,0 @@
// Express - CommonLogger - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
/**
* Months.
*/
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
/**
* Format _date_.
*
* @param {Date} date
* @return {string}
* @api private
*/
function format(date) {
var d = date.getDate(),
m = months[date.getMonth()],
y = date.getFullYear(),
h = date.getHours(),
mi = date.getMinutes(),
s = date.getSeconds()
return (d < 10 ? '0' : '') + d + '/' + m + '/' + y + ' ' +
(h < 10 ? '0' : '') + h + ':' + (mi < 10 ? '0' : '') +
mi + ':' + (s < 10 ? '0' : '') + s
}
// --- CommonLogger
exports.CommonLogger = Plugin.extend({
on: {
/**
* Output log data.
*/
response: function(event) {
puts([event.request.connection.remoteAddress,
'-',
'-',
'[' + format(new Date) + ']',
'"' + event.request.method.toUpperCase() + ' ' + (event.request.url.pathname || '/') +
' HTTP/' + event.request.httpVersion + '"',
event.request.response.status,
event.request.response.headers['content-length'] || 0].join(' '))
}
}
})
+80
Ver Arquivo
@@ -0,0 +1,80 @@
// Express - Logger - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
/**
* Module dependencies.
*/
var sys = require('sys')
/**
* Log formats
*/
var formats = {
common: function(event, start) {
printf('%s - - [%s] "%s %s HTTP/%d" %s %d %0.3f',
event.request.connection.remoteAddress,
(new Date).format('%d/%b/%Y %H:%M:%S'),
event.request.method.uppercase,
event.request.url.pathname || '/',
event.request.httpVersion,
event.request.response.status,
event.request.response.headers['content-length'] || 0,
(Number(new Date) - start) / 1000)
},
combined: function(event, start) {
formats.common(event, start)
printf('"%s" "%s"',
event.request.headers['referrer'] || event.request.headers['referer'] || '-',
event.request.headers['user-agent'])
},
plot: function(event, start) {
sys.print(Number(new Date) - start)
}
}
// --- Logger
exports.Logger = Plugin.extend({
extend: {
/**
* Initialize logger options.
*
* Options:
*
* - format
* 'common' outputs log in CommonLog format (DEFAULT)
* 'combined' outputs log in Apache Combined format
* 'plot' outputs request duration in milliseconds only
*
* @param {hash} options
* @api private
*/
init: function(options) {
this.merge(options || {})
}
},
on: {
/**
* Start timer.
*/
request: function(event) {
this.start = Number(new Date)
},
/**
* Output log data.
*/
response: function(event) {
formats[exports.Logger.format || 'common'](event, this.start)
sys.print('\n')
}
}
})
-51
Ver Arquivo
@@ -1,51 +0,0 @@
// 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) {
this.merge(options || {})
}
},
// --- Events
on: {
/**
* Start timer.
*/
request: function(event) {
this.start = Number(new Date)
},
/**
* Output duration.
*/
response: function(event) {
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)
}
}
})
+2 -5
Ver Arquivo
@@ -168,12 +168,9 @@ exports.Session = Plugin.extend({
*/
startReaper: function() {
var self = this,
oneDay = 86400000,
oneHour = 3600000
setInterval(function(){
self.store.reap(self.lifetime || oneDay)
}, self.reapInterval || self.reapEvery || oneHour)
this.store.reap(this.lifetime || (1).day)
}, this.reapInterval || this.reapEvery || (1).hour, this)
}
},
+16
Ver Arquivo
@@ -178,6 +178,22 @@ exports.Request = Class({
});
},
/**
* Pass control to the next matching route, or
* the given _path_.
*
* NOTE: _path_ may be the request pathname only,
* and may not contain a query string etc.
*
* @param {string} path
* @api public
*/
pass: function(path) {
this.passed = path || true
return this
},
/**
* Set Content-Type header to the mime type
* for the given _path_, which calls mime.type().
+1
Submodule lib/support/ext added at 967039b7d6
+1
Submodule lib/support/haml added at 389c33c6e4
Submódulo
+1
Submodule lib/support/oo added at 1f94bd8979
+1
Submodule lib/support/sass added at 2a648b3766
+14
Ver Arquivo
@@ -0,0 +1,14 @@
{
"name": "Express",
"description": "Sinatra inspired web development framework",
"version": "0.7.3",
"keywords": ["framework", "sinatra", "web", "rest", "restful"],
"directories": {
"lib": "lib"
},
"scripts": {
"install": "git submodule update --init",
"test": "make test"
},
"engines": { "node": ">= 0.1.30" }
}
+1 -6
Ver Arquivo
@@ -1,9 +1,4 @@
---
name: Express
description: Sinatra inspired web development framework
version: 0.6.0
dependencies:
- ext >= 0.2.2
- oo >= 1.2.0
- sass >= 0.3.0
- haml >= 0.1.2
version: 0.7.3
-1
Ver Arquivo
@@ -25,7 +25,6 @@ specs = {
'plugins',
'plugins.cache',
'plugins.view',
'plugins.common-logger',
'plugins.content-length',
'plugins.method-override',
'plugins.body-decoder',
-23
Ver Arquivo
@@ -1,23 +0,0 @@
describe 'Express'
before_each
reset()
use(require('express/plugins/common-logger').CommonLogger)
end
describe 'CommonLogger'
describe 'on'
describe 'response'
it 'should output in common log format'
GLOBAL.stub('puts')
GLOBAL.should.receive('puts')
get('/style.css', function(){
this.contentType('css')
return 'body { background: #000; }'
})
get('/style.css')
end
end
end
end
end
+28 -1
Ver Arquivo
@@ -198,6 +198,33 @@ describe 'Express'
})
get('/public/app.js').body.should.eql 'public, app, js'
end
end
end
describe '#pass()'
it 'should pass control to the next matching route'
get('/user', function(){
this.pass()
})
get('/user', function(){
this.pass()
return 'nodejs'
})
get('/user', function(){ return 'success'})
get('/user').body.should.eql 'success'
end
describe 'given a string'
it 'should pass to the given route'
get('/user', function(){
this.pass('/user/1')
})
get('/user/:id', function(){
return 'Supa doopa usa'
})
get('/user').body.should.eql 'Supa doopa usa'
end
end
end
end
end