-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Allow wildcard url in domain list #38
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution. It's a good feature - I've left a comment on how the implementation could be more complete
One question: what do you think about using a testing framework ? :p
Yeah this project should have some automated tests. Perhaps with cypress.io as the test runner? If you have interest in adding tests, I'd gladly review a PR.
5861cd7
to
e5c2d73
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, I think copying over the regex to string implementation is fine.
@@ -27,16 +29,16 @@ if (domainsElement) { | |||
if (!content) { | |||
console.warn(`Invalid ${domainsMeta} meta element - content required.`); | |||
} | |||
|
|||
const matchHostname = (domain) => | |||
new RegExp(escapeStringRegexp(domain).replace("*", ".+")).test(domain); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you confirmed that this works for a variety of allowlists and domains?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit complicated locally but at least this is the result of manual tests on localhost:5000:
Active When:
- content="allowlist:localhost"
- content="denylist:localhost-*,localhost.*,*.localhost,*-localhost,*localhost,local*host,localhost*"
Inactive When:
- content="denylist:localhost"
- content="allowlist:localhost-*,localhost.*,*.localhost,*-localhost,*localhost,local*host,localhost*"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 seems reasonable. Manipulation of /etc/hosts
file could allow for further testing, but it seems like we've covered most of the cases with those tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idd I tried playing with hosts but I don't know why, I couldn't access to the test server with it. I thought about a host parameter to provide to the "serve" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code broke the allowlist and denylist, as reported in https://single-spa.slack.com/archives/C8R6U7MT7/p1605204526245000.
The reason is that window.location.hostname
is no longer the domain being tested against.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, wildcard domains aren't working because the *
character is escaped before being replaced with .+
Thanks for your work on this. Released in https://github.com/joeldenning/import-map-overrides/releases/tag/v1.17.0 |
Hello,
Just a small proposal to be able to use wildcard URL instead of having to specify the entire hostname in the domain list.
One question: what do you think about using a testing framework ? :p