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

using a known hostname but dynamic port #88

Closed
BrianHicks opened this issue Feb 26, 2024 · 8 comments
Closed

using a known hostname but dynamic port #88

BrianHicks opened this issue Feb 26, 2024 · 8 comments

Comments

@BrianHicks
Copy link
Contributor

At work, we have to develop the frontend through a proxy. That makes webSocketUrl an absolute necessity, so we're using the beta version of elm-watch. However, sometimes the process manager tries to start a new elm-watch instance before the old one has exited, so we get port conflicts and the app fails to start. This isn't the hugest problem—we can just restart the watcher—but it makes me wonder if it'd make sense to specify the components of the URL separately. For example, instead of:

{
  "webSocketUrl": "ws://localhost:3002/elm-watch"
}

I wonder if we could do:

{
  "webSocketUrl": {
    "secure": false,
    "host": "localhost"
  }
}

Or even use the pseudo-syntax that you show in the examples!

{
  "webSocketUrl": "ws://localhost:${port}/elm-watch"
}

Longer-term, I hope to get rid of the process manager that's exhibiting this iffy behavior, but this would help sand down a rough edge in the mean time!

@BrianHicks
Copy link
Contributor Author

hmm, actually, I did a little more searching and I think in the long term we may just want to use the server! But the short-term point still stands.

@lydell
Copy link
Owner

lydell commented Feb 27, 2024

Hi! The idea was to use the ELM_WATCH_WEBSOCKET_URL environment variable when you need something dynamic. Have you tried that?

@lydell
Copy link
Owner

lydell commented Feb 27, 2024

#87 (comment) would allow this to be dynamic as well.

@BrianHicks
Copy link
Contributor Author

Doesn't ELM_WATCH_WEBSOCKET_URL set the same field? How would it make the port dynamic?

@lydell
Copy link
Owner

lydell commented Feb 27, 2024

Then I must have failed again understanding exactly what you meant 😅

@BrianHicks
Copy link
Contributor Author

ah, ok. Let me add more details then:

  • I have to develop this app through a proxy to make a couple things work right. I'm not up on all the details exactly, but basically app.mycorp-dev.com is my "local" URL.
  • I run something on my computer that overrides that URL, but only for :80 and some other special ports
  • I can get elm-watch working if I set the host to to localhost. Then I don't have to mess with the proxy.
  • At that point, I care a lot about the hostname, but I don't care at all about the port, until…
  • When I make a change, sometimes there is a port conflict and then the whole process supervision scheme crashes and I have to restart it

If I could set a fixed host but a dynamic port, that'd be fine! I don't really care what the port is, just the host.

I admit this is a very specific set of requirements, though. 😆

@lydell
Copy link
Owner

lydell commented Feb 27, 2024

Hmm, so is this correct?

  1. Your dev site is on app.mycorp-dev.com
  2. By default elm-watch connects to the same hostname, but you want it to connect to localhost
  3. You can configure the hostname via webSocketUrl, but then you also have to set the port
  4. By default elm-watch gets a free port from the OS, but you have to set the port to a known value so that you can use webSocketUrl, but that sometimes results in a port conflict
  5. So you want to be able to use the hostname but not the port, because you think that would avoid the port conflict?

If so, I’m not sure that would help. When elm-watch gets a free port from the OS, it saves that port in elm-stuff/elm-watch/stuff.json, so it can connect to the same port next time. So I’m thinking you’d get port conflicts anyway?

But with #87 (comment) you’d be able to set a new, free port every time. However, then you end up with old compiled JS trying to connect to the old port, which isn’t ideal. (That’s why elm-watch saves the port it got.)

@BrianHicks
Copy link
Contributor Author

Yeah, you've got it. And that makes sense. Hmm. Well, I think this isn't a forever issue; I'm eventually going to have to rework how the processes are spawned and at that point we'll have a better chance to clean up.

I'm going to close this for now since given what you've said the requested change would not fix the problem!

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

No branches or pull requests

2 participants