From 27caff3d59090715549865b1cc713861069df233 Mon Sep 17 00:00:00 2001 From: Adam Lau Date: Wed, 7 Sep 2016 16:20:44 +0800 Subject: [PATCH] fix: should get subdomains from hostname instead (#809) This helps avoid dealing with the port in this.host --- lib/request.js | 6 +++--- test/request/subdomains.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/request.js b/lib/request.js index 830b21b..d1a73ff 100644 --- a/lib/request.js +++ b/lib/request.js @@ -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); diff --git a/test/request/subdomains.js b/test/request/subdomains.js index 39b4b6b..767a6cb 100644 --- a/test/request/subdomains.js +++ b/test/request/subdomains.js @@ -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([]); }); })