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 server transformer not respecting host and port overrides #33425

Merged
merged 5 commits into from Mar 23, 2021

Conversation

erwinmombay
Copy link
Member

currently when a port and host override is passed in from gulp serve the transformer does not currently apply the values to the transformed document. this breaks some port forwarding scenarios as well as being able to override the host and port values manually.

Copy link
Contributor

@rsimha rsimha left a comment

Choose a reason for hiding this comment

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

LGTM with two nits.

build-system/server/new-server/transforms/transform.ts Outdated Show resolved Hide resolved
build-system/server/new-server/transforms/transform.ts Outdated Show resolved Hide resolved
const ESM = !!argv.esm;

const defaultTransformConfig = {
esm: ESM,
host: HOST,
Copy link
Contributor

Choose a reason for hiding this comment

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

Host is not static, it's per request. Eg, hosting on 0.0.0.0 (the now default) allows connections on 192.168.1.100 (or whatever your local IP is). So test on a phone would request http://192.168.1.100:8000, and we should respond with URLs using that requesting domain.

Copy link
Member Author

Choose a reason for hiding this comment

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

i went ahead and remove the overriding host code and removed reading from global argv

@@ -76,12 +76,12 @@ export function toExtension(url: URL, extension: string): URL {
* This is a temporary measure to allow for a relaxed parsing of our
* fixture files' src urls before they are all fixed accordingly.
*/
export function tryGetUrl(src: string, port: number = 8000): URL {
export function tryGetUrl(src: string, host: string = '0.0.0.0', port: number = 8000): URL {
Copy link
Contributor

Choose a reason for hiding this comment

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

Depending on the caller, this is unneeded. If you already know the absolute path, just use /path/to/script.mjs. That means the returned URL will always be on whatever host is currently being requested, without you having to know about it.

Copy link
Member Author

Choose a reason for hiding this comment

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

went ahead and applied your suggestion. PTAL

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a separate concern. What I mean here is that the caller of tryGetUrl probably doesn't need to call it at all. Instead, they can just use an host-relative absolute path (eg, /path/to/script.js).

Copy link
Contributor

@Enriqe Enriqe left a comment

Choose a reason for hiding this comment

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

Thanks @erwinmombay !

@Enriqe Enriqe requested review from Enriqe and removed request for Enriqe March 22, 2021 21:27
@@ -55,7 +55,7 @@ export function CDNURLToLocalDistURL(
useMaxNames = false,
): URL {
url.protocol = 'http';
url.hostname = 'localhost';
url.hostname = '0.0.0.0';
Copy link
Member Author

Choose a reason for hiding this comment

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

@jridgewell is this correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

also question does anyone know if 0.0.0.0 works on windows?

/cc @rsimha

Copy link
Contributor

Choose a reason for hiding this comment

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

No, this isn't right. If i request the page from my phone, 0.0.0.0 is going to tell me to look up this URL on my phone server, which doesn't exist. You need to know the host of the page is currently being requested, and rewrite the URL relative to that host.

Copy link
Contributor

@rsimha rsimha Mar 22, 2021

Choose a reason for hiding this comment

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

We run integration tests on Windows, so you can look at logs from older CI builds. This build suggests that Windows doesn't use 0.0.0.0, but it does use 127.0.0.1.

image

@erwinmombay erwinmombay force-pushed the fix-port-host-new-server branch 2 times, most recently from b4a9f5b to 2cf1359 Compare March 23, 2021 18:03
@@ -77,6 +77,17 @@ export function CDNURLToLocalDistURL(
return url;
}

export function CDNURLToLocalHostRelativeAbsoluteDist(
Copy link
Contributor

Choose a reason for hiding this comment

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

This function name is a mouthful to say, but I don't have any better suggestions 😃

Copy link
Contributor

@rsimha rsimha left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for making this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants