Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion lib/optionsSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
8 changes: 7 additions & 1 deletion test/Validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down