Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added app.listen() as a shortcut for http.createServer(app).listen()

  • Loading branch information...
commit 9082e74971f4273ccc556bfd9b1f9f6e1f3d628f 1 parent 7a7d77e
@tj tj authored
Showing with 44 additions and 10 deletions.
  1. +26 −10 lib/application.js
  2. +18 −0 test/app.listen.js
View
36 lib/application.js
@@ -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');
@@ -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
*/
@@ -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
*/
@@ -261,7 +262,7 @@ app.mounted = function(fn){
*
* @param {String} ext
* @param {Function} fn
- * @return {Server} for chaining
+ * @return {app} for chaining
* @api public
*/
@@ -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
*/
@@ -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
*/
@@ -421,7 +422,7 @@ app.disabled = function(setting){
* Enable `setting`.
*
* @param {String} setting
- * @return {Server} for chaining
+ * @return {app} for chaining
* @api public
*/
@@ -433,7 +434,7 @@ app.enable = function(setting){
* Disable `setting`.
*
* @param {String} setting
- * @return {Server} for chaining
+ * @return {app} for chaining
* @api public
*/
@@ -446,7 +447,7 @@ app.disable = function(setting){
*
* @param {String} key
* @param {String} url
- * @return {Server} for chaining
+ * @return {app} for chaining
* @api public
*/
@@ -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
*/
@@ -491,6 +492,21 @@ app.configure = function(env, fn){
};
/**
+ * 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, ...)`.
*/
@@ -509,7 +525,7 @@ methods.forEach(function(method){
*
* @param {String} path
* @param {Function} ...
- * @return {Server} for chaining
+ * @return {app} for chaining
* @api public
*/
View
18 test/app.listen.js
@@ -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();
+ });
+ })
+})
Please sign in to comment.
Something went wrong with that request. Please try again.