-
Notifications
You must be signed in to change notification settings - Fork 31
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
Inherit host & protocol from endpoint #6
Comments
This would be very useful for us as well. We build containers with our application so we strive to use the same code independently of the environment. |
This looks pretty straight forward. Can you open a PR? |
Honestly I'm not too sure how to go with this. As far as I know there's no way to get I tried the latter approach but I'm still far from a PR, I don't know how I'm supposed to debug/test if it works. Any thoughts? |
Hmm... I originally thought that you could connect a WebSocket with a relative path, but according to this StackOverflow answer, you can only use absolute URLs. Here's what I think we should do:
You can get the current location by using this package: |
Generally speaking, I feel like this is something that should be handled by environment variables instead of the library itself. Determining if the socket server is relative vs absolute will work for some environments, but not for all. For example, your development environment may run on Doing this with node and webpack is easy. You can use something like dotenv to load your configuration into environment variables. I don't know if something like this exists for Elm yet. |
I wonder why phoenix.js can get away with relative URLs for the websocket (https://github.com/phoenixframework/phoenix/blob/master/web/static/js/phoenix.js#L492). Is it a limitation of Elm's Websocket class? |
They use a regex to determine if the provided URL is a relative or absolute path. If it's a relative path, they append the https://github.com/phoenixframework/phoenix/blob/master/web/static/js/phoenix.js#L490-L499 |
@simonewebdesign Can't you get around this by passing the location as a program flag and keeping the websocket url in the model? See http://package.elm-lang.org/packages/elm-lang/html/1.1.0/Html-App#programWithFlags (hello btw! 👋 ) |
@cloud8421 That's actually not a bad idea. Ideally I'd like this library to mirror the functionality of the phoenix.js library, but integrating the navigation package seems like kind of a pain. Rather than providing for the current path as a subscription, it requires you to use an entirely separate |
If anyone has an ideas on how to cleanly integrate navigation into this library, please let me know or open a PR. |
+1 for this |
Is there any progress on the issue folks? |
In our project we use navigation, so we ended up using |
I don't want to be able to have multiple URLs go to my site. |
Hi, we just integrated elm-phoenix-socket yesterday without any issues :)
Is it possible to inherit host and protocol from
socketServer
? E.g.:Would it be possible to omit the first part, so that this would work too:
Phoenix.js does that, and the advantage for us is that we don't need to do any crazy things to change the endpoint depending on the environment.
The text was updated successfully, but these errors were encountered: