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..d28bb6602e 100644 --- a/lib/optionsSchema.json +++ b/lib/optionsSchema.json @@ -144,7 +144,18 @@ }, "public": { "description": "The public hostname/ip address of the server.", - "type": "string" + "anyOf": [ + { + "items": { + "type": "string" + }, + "minItems": 1, + "type": "array" + }, + { + "type": "string" + } + ] }, "https": { "description": "Enable HTTPS for server.", 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",