I’ve created a Phoenix Umbrella project containing two applications. They will both be served as separate endpoints. To share assets between them, I’ve created a new application called “assets”, which sole purpose is to have the “/priv/static” directory. Now I would like to share the assets with both endpoints, and I already configured the static plug for that;
plug Plug.Static,
at: "/",
from: :example_assets,
gzip: true,
only: ~w(css fonts images js favicon.ico robots.txt)
This works perfect in development. But when I build and start an release of one the endpoints, I run into the following error;
[error] Could not find static manifest at "/app/example_web/lib/example_web-0.1.0/priv/static/cache_manifest.json". Run "mix phx.digest" after building your static files or remove the configuration from "config/prod.exs".
How do I make my “example_web” endpoint aware of the cache manifest file in the “example_assets” directory? Thanks in advance for any help!
I guess the cache manifest doesn’t yet support static assets in another application:
https://github.com/phoenixframework/phoenix/blob/3e1257c499ed51a67b072d73bf9b0397f68476dd/lib/phoenix/endpoint/supervisor.ex#L453-L467
You cannot use relative paths without Application.app_dir as mix and releases use different folder structures.
@LostKobrakai yeah I found about that as well
so I’ve made the “example_assets” app an endpoint. But how do I route these assets requests from the “example_web” endpoint to the “example_assets” endpoint?
You don’t. You should only use one endpoint and not forward to another one. You could forward to different routers though. Imo the better option would be a PR to phoenix to enable the config of e.g. {:app, path} for : cache_static_manifest.
You’re correct, it is indeed not possible to forward any requests to another endpoint. I’ve created a PR in the Phoenix project to allow cache manifests from different apps (Load cache manifest from specified application by robinvdvleuten · Pull Request #3618 · phoenixframework/phoenix · GitHub).