tompave / fun_with_flags_ui

Web dashboard for the FunWithFlags Elixir package

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

https://github.com/phoenixframework/phoenix_live_dashboard/blob/main/lib/phoenix/live_dashboard/controllers/assets.ex

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.

  1. What versions of the lib, Plug (and Phoenix?) you're using.
  2. In your Plug or Phoenix router, at what path have you mounted FunWithFlags.UI.Router?
  3. What URL is the FWF.UI landing page served at, when you access it with a browser?
  4. In the FWF.UI landing page, what URL is generated for the assets?
  5. 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!