From 569f9c23c687c964e3d2d41ec451c7431d385a4c Mon Sep 17 00:00:00 2001 From: Teddy Ortega Date: Fri, 28 Apr 2017 16:32:25 -0400 Subject: [PATCH 1/2] Allow passing multiple hosts to 'public' --- lib/Server.js | 15 ++++++++++++--- lib/optionsSchema.json | 9 ++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index 1a2fe5ccab..07b9810c97 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -414,11 +414,20 @@ Server.prototype.checkHost = function(headers) { // allow hostname of listening adress if(hostname === this.listenHostname) return true; + const hostIsPublicHost = host => { + const idxPublic = host.indexOf(":"); + const publicHostname = idxPublic >= 0 ? host.substr(0, idxPublic) : host; + if(hostname === publicHostname) return true; + } // also allow public hostname if provided if(typeof this.publicHost === "string") { - const idxPublic = this.publicHost.indexOf(":"); - const publicHostname = idxPublic >= 0 ? this.publicHost.substr(0, idxPublic) : this.publicHost; - if(hostname === publicHostname) return true; + if(hostIsPublicHost(this.publicHost)) return true; + } + // allow multiple public hostnames + if(Array.isArray(this.publicHost)) { + for(let hostIdx = 0; hostIdx < this.publicHost.length; hostIdx++) { + if(hostIsPublicHost(this.publicHost[hostIdx])) return true; + } } // disallow diff --git a/lib/optionsSchema.json b/lib/optionsSchema.json index 49c60db1ee..ae298881ee 100644 --- a/lib/optionsSchema.json +++ b/lib/optionsSchema.json @@ -144,7 +144,14 @@ }, "public": { "description": "The public hostname/ip address of the server.", - "type": "string" + "anyOf": [ + { + "type": "array" + }, + { + "type": "string" + } + ] }, "https": { "description": "Enable HTTPS for server.", From 179ed81ba6298bf13e167e521659437cb4b73671 Mon Sep 17 00:00:00 2001 From: Teddy Ortega Date: Fri, 28 Apr 2017 17:24:00 -0400 Subject: [PATCH 2/2] correct 'public' in optionsSchema.json and update Validation.test.js --- lib/optionsSchema.json | 4 ++++ test/Validation.test.js | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/optionsSchema.json b/lib/optionsSchema.json index ae298881ee..d28bb6602e 100644 --- a/lib/optionsSchema.json +++ b/lib/optionsSchema.json @@ -146,6 +146,10 @@ "description": "The public hostname/ip address of the server.", "anyOf": [ { + "items": { + "type": "string" + }, + "minItems": 1, "type": "array" }, { diff --git a/test/Validation.test.js b/test/Validation.test.js index 2be20c4fc3..18ed188daa 100644 --- a/test/Validation.test.js +++ b/test/Validation.test.js @@ -20,7 +20,13 @@ describe("Validation", function() { name: "invalid `public` configuration", config: { public: 1 }, message: [ - " - configuration.public should be a string." + " - configuration.public should be one of these:", + " [string] | string", + " The public hostname/ip address of the server.", + " Details:", + " * configuration.public should be an array:", + " [string]", + " * configuration.public should be a string." ] }, { name: "invalid `contentBase` configuration",