Skip to content

Commit

Permalink
Added app.listen() as a shortcut for http.createServer(app).listen()
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Nov 12, 2011
1 parent 7a7d77e commit 9082e74
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
36 changes: 26 additions & 10 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var connect = require('connect')
, url = require('url')
, utils = connect.utils
, path = require('path')
, http = require('http')
, join = path.join
, fs = require('fs')
, qs = require('qs');
Expand Down Expand Up @@ -180,7 +181,7 @@ app.match = function(url){
*
* @param {String|Function|Server} route
* @param {Function|Server} middleware
* @return {Server} for chaining
* @return {app} for chaining
* @api public
*/

Expand Down Expand Up @@ -239,7 +240,7 @@ app.use = function(route, middleware){
* app.use(blog);
*
* @param {Function} fn
* @return {Server} for chaining
* @return {app} for chaining
* @api public
*/

Expand All @@ -261,7 +262,7 @@ app.mounted = function(fn){
*
* @param {String} ext
* @param {Function} fn
* @return {Server} for chaining
* @return {app} for chaining
* @api public
*/

Expand Down Expand Up @@ -326,7 +327,7 @@ app.engine = function(ext, fn){
*
* @param {String|Array|Function} name
* @param {Function} fn
* @return {Server} for chaining
* @return {app} for chaining
* @api public
*/

Expand Down Expand Up @@ -360,7 +361,7 @@ app.param = function(name, fn){
*
* @param {String} type
* @param {Function} fn
* @return {Server} for chaining
* @return {app} for chaining
* @api public
*/

Expand Down Expand Up @@ -421,7 +422,7 @@ app.disabled = function(setting){
* Enable `setting`.
*
* @param {String} setting
* @return {Server} for chaining
* @return {app} for chaining
* @api public
*/

Expand All @@ -433,7 +434,7 @@ app.enable = function(setting){
* Disable `setting`.
*
* @param {String} setting
* @return {Server} for chaining
* @return {app} for chaining
* @api public
*/

Expand All @@ -446,7 +447,7 @@ app.disable = function(setting){
*
* @param {String} key
* @param {String} url
* @return {Server} for chaining
* @return {app} for chaining
* @api public
*/

Expand Down Expand Up @@ -477,7 +478,7 @@ app.redirect = function(key, url){
*
* @param {String} env...
* @param {Function} fn
* @return {Server} for chaining
* @return {app} for chaining
* @api public
*/

Expand All @@ -490,6 +491,21 @@ app.configure = function(env, fn){
return this;
};

/**
* Listen for connections.
*
* This method takes the same arguments
* as node's `http.Server#listen()`.
*
* @return {http.Server}
* @api public
*/

app.listen = function(){
var server = http.createServer(this);
return server.listen.apply(server, arguments);
};

/**
* Delegate `.VERB(...)` calls to `.route(VERB, ...)`.
*/
Expand All @@ -509,7 +525,7 @@ methods.forEach(function(method){
*
* @param {String} path
* @param {Function} ...
* @return {Server} for chaining
* @return {app} for chaining
* @api public
*/

Expand Down
18 changes: 18 additions & 0 deletions test/app.listen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

var express = require('../')
, request = require('./support/http');

describe('app.listen()', function(){
it('should wrap with an HTTP server', function(done){
var app = express();

app.del('/tobi', function(req, res){
res.end('deleted tobi!');
});

var server = app.listen(9999, function(){
server.close();
done();
});
})
})

0 comments on commit 9082e74

Please sign in to comment.