Closed Ploppz closed 3 years ago
This is correct. The browser makes a request to http://localhost:8000/api/v1/measurements
, served by elm-live
. Then under the hood the elm-live
server will proxy the request to http://localhost:8443/api/v1/measurements
.
Ah, I understand.
But I still have a problem: The requests it sends return 404.
For example I see in the Network tab GET http://localhost:8000/api/v1/measurements
that resulted in 404.
But if I run curl http://localhost:8443/api/v1/measurements
, it is successful.
It looks like proxy prefix is deleted from URL: https://github.com/wking-io/elm-live/blob/master/lib/src/start.js#L187
i.e. http://localhost:8000/api/v1/measurements
would be proxied to http://localhost:8443/v1/measurements
with --proxy-prefix '/api'
Huh, that makes little sense. Thanks for figuring that out.
Now I'm unsure how I can achieve what I want:
I want to locally run the app with elm-live
and proxy all requests to an API running on a different port.
In production, I want the same Elm code to send a request to the path part of URL: /api/v1/
, so if it's running on example.com
and sends a request to /api/v1/something
, it gets sent to example.com/api/v1/something
@Ploppz Add /api
to the proxy-host as well, like so:
elm-live src/Main.elm --proxy-prefix '/api' --proxy-host 'http://localhost:8443/api' -- --output elm.js
See https://www.elm-live.com/#getting-started and scroll down to documentation for --proxy-prefix
:
NOTE: The string passed to
--proxy-prefix
will be removed from the--proxy-host
url. If you would like the url to include the prefix just add it there as well like: http://localhost:5000/api
Ahh missed that, sorry
No problem! Glad to hear you're up & running. 👋
Proxying does not seem to have any effect in my project. The following files make a fully reproducible example. I have an API running on localhost:8443 and want to send request over there by specifying only the path part of the URL.
elm.json
index.html
:Main.elm
:Then I run:
Problem is that in Firefox debugging window under Network tab I can see that it actually sends a request to
http://localhost:8000/api/v1/measurements
.