fix: should get subdomains from hostname instead (#809)

This helps avoid dealing with the port in this.host
This commit is contained in:
Adam Lau 2016-09-07 16:20:44 +08:00 committed by Yiyu He
parent 4c665cc2ef
commit 27caff3d59
2 changed files with 5 additions and 5 deletions

View file

@ -418,9 +418,9 @@ module.exports = {
get subdomains() {
var offset = this.app.subdomainOffset;
var host = this.host || '';
if (net.isIP(host)) return [];
return host
var hostname = this.hostname;
if (net.isIP(hostname)) return [];
return hostname
.split('.')
.reverse()
.slice(offset);

View file

@ -19,9 +19,9 @@ describe('req.subdomains', function(){
req.subdomains.should.eql([]);
})
it('should check if the host is an ip address', function(){
it('should check if the host is an ip address, even with a port', function(){
var req = request();
req.header.host = '127.0.0.1';
req.header.host = '127.0.0.1:3000';
req.subdomains.should.eql([]);
});
})