Merge branch 'master' into 2.0
Land the pull request #357 > app: update `url` on `listening` event
This commit is contained in:
commit
8ea11ea955
|
@ -466,6 +466,13 @@ app.listen = function(cb) {
|
||||||
|
|
||||||
server.on('listening', function() {
|
server.on('listening', function() {
|
||||||
self.set('port', this.address().port);
|
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 =
|
var useAppConfig =
|
||||||
|
|
|
@ -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) {
|
it('forwards to http.Server.listen on more than one arg', function(done) {
|
||||||
var app = loopback();
|
var app = loopback();
|
||||||
app.set('port', 1);
|
app.set('port', 1);
|
||||||
|
|
Loading…
Reference in New Issue