Assets don't work when hosting with a subpath
egze opened this issue · comments
We have a bit of a strange setup, where the app is hosted on a subpath. some.site.com/cool-app
It's also not a clever url rewrite, so the logic how to handle subpaths is a responsibility of the applications and the /cool-app
part is actually in our router scopes. It is also part of our urls for static assets.
Now, this is a challenge when using fun_with_flags_ui. The assets are hardcoded and I can't inject the /cool-app
prefix to them. Or can I, and I just don't know how?
I did a bit of research and looked how phoenix_live_dashboard does it, because the usage pattern is similar, but the assets work for them.
They made a plug for serving static assets, so it works wherever it is mounted.
If this is the solution, I would be happy to come up with a PR.
Hi, thank you for using the library and opening the issue.
I think I need more information.
- What versions of the lib, Plug (and Phoenix?) you're using.
- In your Plug or Phoenix router, at what path have you mounted
FunWithFlags.UI.Router
? - What URL is the FWF.UI landing page served at, when you access it with a browser?
- In the FWF.UI landing page, what URL is generated for the assets?
- What error are you getting? A 404 from the host application?
If possible, could you please illustrate the problem with a sample app? One commit for the sample app scaffold (e.g. the output of mix phx.new foobar
), and then additional commits to show your setup.
OK, I got it to work on a subpath.
Here are the routes
scope "/subpath" do
scope "/admin" do
pipe_through [:browser, :require_authenticated_admin]
# some other admin routes
end
scope "/admin/feature-flags" do
pipe_through [:browser, :require_authenticated_admin]
forward "/", FunWithFlags.UI.Router, namespace: "subpath/admin/feature-flags"
end
end
The key was to set proper namespace for the FunWithFlags.UI.Router
. Once set correctly, the assets urls were also generated correctly. So I think it was improper usage from my part and the issue can be closed.
I'm glad it's working and the problem is solved!