Skip to content

Commit

Permalink
Proxy server errors to express app
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleytodd committed Apr 19, 2015
1 parent 8dd1b3a commit 02d76ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ app.render = function(name, options, fn){

app.listen = function(){
var server = http.createServer(this);
server.on('error', this.emit.bind(this, 'error'));
return server.listen.apply(server, arguments);
};

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

var express = require('../')
, assert = require('assert')
, request = require('supertest');

describe('app.listen()', function(){
Expand All @@ -15,4 +16,19 @@ describe('app.listen()', function(){
done();
});
})

it('should proxy HTTP server errors', function(done){
var app = express();
var app2 = express();

app2.on('error', function(err) {
assert(err.code === 'EADDRINUSE');
server.close();
done();
});

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

0 comments on commit 02d76ae

Please sign in to comment.