Merge branch 'master' into 2.0

Land the pull request #357
> app: update `url` on `listening` event
This commit is contained in:
Miroslav Bajtoš 2014-07-01 16:18:00 +02:00
commit 8ea11ea955
2 changed files with 19 additions and 0 deletions

View File

@ -466,6 +466,13 @@ app.listen = function(cb) {
server.on('listening', function() {
self.set('port', this.address().port);
if (!self.get('url')) {
// A better default host would be `0.0.0.0`,
// but such URL is not supported by Windows
var host = self.get('host') || '127.0.0.1';
var url = 'http://' + host + ':' + self.get('port') + '/';
self.set('url', url);
}
});
var useAppConfig =

View File

@ -208,6 +208,18 @@ describe('app', function() {
});
});
it('updates "url" on "listening" event', function(done) {
var app = loopback();
app.set('port', 0);
app.set('host', undefined);
app.listen(function() {
expect(app.get('url'), 'url')
.to.equal('http://127.0.0.1:' + app.get('port') + '/');
done();
});
});
it('forwards to http.Server.listen on more than one arg', function(done) {
var app = loopback();
app.set('port', 1);