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

Get websocket port from document.currentScript if possible #30

Closed
mmhand123 opened this issue Dec 20, 2019 · 7 comments · Fixed by #133
Closed

Get websocket port from document.currentScript if possible #30

mmhand123 opened this issue Dec 20, 2019 · 7 comments · Fixed by #133

Comments

@mmhand123
Copy link
Contributor

Sorry if this is a duplicate. I saw there was #10 but I think this is a little different. With webpack-dev-server we're running it off another port locally. I looked at how wds tries to establish the socket and noticed __resourceQuery, but also that it falls back to trying to use document.currentScript. For the time being would it be ok to add in trying to parse document.currentScript and fall back to the current behavior? Happy to PR this, just wanted to check if it was something you'd want 😁

@pmmmwh
Copy link
Owner

pmmmwh commented Dec 22, 2019

Yea - this is something on my radar. I do have a TODO in the source code tracking this. I'm also waiting for webpack/webpack-dev-server#2055 to land so that public path can be properly supported. I have some code written already - if you want to pick this up I can share them cause atm I'm focusing on #7 and #10

@markovicdenis
Copy link

Another idea would be to add settings options for "hostname" and "port" for the socket connection...

In my particular configuration, the deserver is running on different port with different hostname as well.

@mmhand123
Copy link
Contributor Author

@pmmmwh yeah I'd be happy to pick it up and work on it. Would be great to see what you've already done!

@markovicdenis Yeah - you can actually get those from document.currentScript too. I just mentioned port because it was the thing custom in the webpack config I was working with 😅 Could potentially do both though, add the options and fallback to current script or something.

@carrickjason
Copy link

carrickjason commented Jan 13, 2020

@mmhand123 I was able to utilize the devServer.sockPath and devServer.sockPort config to setup the socket in createSocket.js using __resourceQuery. I didn't have any luck with document.currentScript because it always just returned the name of the bundle this entry file ends up in and doesn't include the added query. (ie main.bundle.js).

@pmmmwh Would you like a PR for this?

@ro-savage
Copy link
Contributor

@carrickjason - Would be great if you could do a PR for this. We are running into the same issue.

@pmmmwh
Copy link
Owner

pmmmwh commented Feb 21, 2020

@pmmmwh Would you like a PR for this?

Yes, it would help. This implementation could also help - it seems to fit our use cases well in terms of handling custom servers and also __resourceQuery.

@ro-savage
Copy link
Contributor

When I tried to access __resourceQuery inside createSocket.js it just comes back as null.
Using document.currentScript no port is provided (at least on our implementation of webpack using rail's webpacker).

I'd wouldn't mind trying to implement this, but at a bit of a loss. Unless we just allow custom ports.

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

Successfully merging a pull request may close this issue.

5 participants