Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: normalize for allowedHosts #3720

Merged
merged 3 commits into from
Aug 23, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ class Server {
options.allowedHosts = [options.allowedHosts];
}

// for cases when it's a singleton array with `all` or `auto`
if (
Array.isArray(options.allowedHosts) &&
options.allowedHosts.length === 1 &&
(options.allowedHosts[0] === "auto" || options.allowedHosts[0] === "all")
) {
options.allowedHosts = options.allowedHosts[0];
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also account for allowedHosts: ['host1.com', 'host2.com', 'all']:

if (this.options.allowedHosts === "all") {

- if (this.options.allowedHosts === "all") { 
+ if (
+ this.options.allowedHosts === "all" || 
+ (Array.isArray(this.options.allowedHosts) && this.options.allowedHosts.includes("all"))
+ ) { 

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all and other hosts are mutually exclusive, I don't think there would be a use case for specifying other hosts with all 🤔 Maybe this would be the case for auto when we need to allow localhost along with other hosts

Copy link
Member

@snitin315 snitin315 Aug 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's hear more opinions here 👍🏻

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @alexander-akait need slight attention 

is this okay or should we handle 'auto' too here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will look at this in near future

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add tests once you confirm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was mistake adding auto (because we already allow to handle from localhost/ip/etc), we should revisit this in the next major release, I will finish PR

if (typeof options.bonjour === "undefined") {
options.bonjour = false;
} else if (typeof options.bonjour === "boolean") {
Expand Down