phoenixframework / phoenix_live_reload

Provides live-reload functionality for Phoenix
MIT License
315 stars 90 forks source link

Handle `script_name` when passing `:path` option to endpoint #121

Closed c4710n closed 2 years ago

c4710n commented 2 years ago

When I configured an endpoint like this:

config :admin_web, AdminWeb.Endpoint,
  url: [scheme: "http", host: "localhost", port: 4000, path: "/admin"]

This package didn't work as expected, the browser complained something like:

/admin/phoenix/live_reload/frame 404 not found

Then, I found the problem - live_reloader.ex#L91

When I configured my app with above code:

Finally, I solve this problem with script_name, which is derived from :path option in config :admin_web, AdminWeb.Endpoint.

I think the code can be improved a lot, but I can't do it better for now.

@ me, if you think the code can be improved. Hope this PR can be merged. ;)

josevalim commented 2 years ago

Thank you for the PR but I believe this is working as intended. :) url: [scheme: "http", host: "localhost", port: 4000, path: "/admin"] configures the URL generation. If you have "/admin", then it means something before Phoenix is processing the request and removing the "/admin" part from it. :) So you need to either remove the :path or have something before Phoenix (like a nginx reverse proxy) that removes it from you, otherwise more stuff is going to break!

c4710n commented 2 years ago

Thank you very much for explaining it. 😄 I got the point.