Skip to content

Commit

Permalink
Add 'allowedHosts' option
Browse files Browse the repository at this point in the history
  • Loading branch information
orteth01 committed Jun 14, 2017
1 parent 9a7693c commit 36cb650
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function Server(compiler, options) {
this.clientOverlay = options.overlay;
this.disableHostCheck = !!options.disableHostCheck;
this.publicHost = options.public;
this.allowedHosts = options.allowedHosts;
this.sockets = [];
this.contentBaseWatchers = [];

Expand Down Expand Up @@ -443,6 +444,9 @@ Server.prototype.checkHost = function(headers) {
// always allow localhost host, for convience
if(hostname === "127.0.0.1" || hostname === "localhost") return true;

// allow if hostname is in allowedHosts
if(this.allowedHosts && this.allowedHosts.indexOf(hostname) >= 0) return true;

// allow hostname of listening adress
if(hostname === this.listenHostname) return true;

Expand Down
7 changes: 7 additions & 0 deletions lib/optionsSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
"description": "The host the server listens to.",
"type": "string"
},
"allowedHosts": {
"description": "Specifies which hosts are allowed to access the dev server.",
"items": {
"type": "string"
},
"type": "array"
},
"filename": {
"description": "The filename that needs to be requested in order to trigger a recompile (only in lazy mode).",
"anyOf": [
Expand Down
10 changes: 9 additions & 1 deletion test/Validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ describe("Validation", function() {
message: [
" - configuration.public should be a string."
]
}, {
name: "invalid `allowedHosts` configuration",
config: { allowedHosts: 1 },
message: [
" - configuration.allowedHosts should be an array:",
" [string]",
" Specifies which hosts are allowed to access the dev server."
]
}, {
name: "invalid `contentBase` configuration",
config: { contentBase: [0] },
Expand All @@ -40,7 +48,7 @@ describe("Validation", function() {
config: { asdf: true },
message: [
" - configuration has an unknown property 'asdf'. These properties are valid:",
" object { hot?, hotOnly?, lazy?, host?, filename?, publicPath?, port?, socket?, " +
" object { hot?, hotOnly?, lazy?, host?, allowedHosts?, filename?, publicPath?, port?, socket?, " +
"watchOptions?, headers?, clientLogLevel?, overlay?, key?, cert?, ca?, pfx?, pfxPassphrase?, " +
"inline?, disableHostCheck?, public?, https?, contentBase?, watchContentBase?, open?, features?, " +
"compress?, proxy?, historyApiFallback?, staticOptions?, setup?, stats?, reporter?, " +
Expand Down

0 comments on commit 36cb650

Please sign in to comment.