phoenixframework / phoenix_live_reload

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

Unable to specify custom prefix for `live_reload/frame` url #124

Closed VictorGaiva closed 2 years ago

VictorGaiva commented 2 years ago

When using a non default HTML Base URL, it is not possible to load phoenix/live_reload/frame since the path fragment here cannot be customized.

chrismccord commented 2 years ago

Can you share more about what you are doing and the kind of path_info the server is seeing? Thanks!

VictorGaiva commented 2 years ago

I have a React dev server using Vite listening on localhost:5000. It rewrites /api/reports to localhost:4002/api/reports where Phoenix server is listening. I have prefixed my Endpoint and routes with /api/reports, and all assets and HTML load successfully.

But live_reload is not able to load the /api/reports/phoenix/live_reload/frame, giving 404

Screenshot from 2022-04-06 14-09-02

I've locally made a proof of concept that allows a :prefix to be defined in the config the same way :suffix is currently defined. This allowed me to make it work in my current setup. I'll be opening a PR so you can take a look

VictorGaiva commented 2 years ago

Diggin deeper I found this test which validates that the phoenix/live_reload/frame URL is prefixed with the endpoint's path, that happens correctly in my setup, but it doesn't check if it possible to correctly load the resource.

josevalim commented 2 years ago

I have prefixed my Endpoint and routes with /api/reports, and all assets and HTML load successfully.

This is not the correct approach. :) Instead, you should have a plug in your endpoint that strips "/api/reports" from path info and automatically add it as the conn.script_name. This way all routes work and are generated correctly without having to prefix your routes with /api/reports