reflex icon indicating copy to clipboard operation
reflex copied to clipboard

FRONTEND_PATH is not applied for assets URLs

Open juangon opened this issue 1 year ago β€’ 8 comments

Describe the bug When using frontend_path parameter (in my case used as env variable), when referencing assets in /assets folder, frontend_path is not added, throwing 404 errors for those resources

To Reproduce Execute reflex populating FRONTEND_PATH env variable. Add some assets in /assets folder and reference them as stated in documents (prefixing them with slash '/').

Expected behavior Assets path should add FRONTEND_PATH to the referenced resources.

Screenshots

Specifics (please complete the following information):

  • Python Version:3.12
  • Reflex Version: 0.6.5
  • OS: Linux
  • Browser (Optional):

Additional context Add any other context about the problem here.

juangon avatar Dec 01 '24 07:12 juangon

In order to give more clues, this doesn't work in two parts:

  • favicon (located in /assets)
  • Resources referenced from css that are located in /assets too, like:
@font-face {
    font-family: inetum;
    font-weight: bold;
    src: url("/fonts/Poppins-Bold.ttf") format("truetype");
}

In font case, unless I am prefixing the url with FRONTEND_PATH, it won't work.

juangon avatar Dec 01 '24 17:12 juangon

@juangon can you try with rx.asset and this PR https://github.com/reflex-dev/reflex/pull/4460 ?

benedikt-bartscher avatar Dec 01 '24 18:12 benedikt-bartscher

Thanks @benedikt-bartscher , but how can I use rx.asset inside a CSS file?

juangon avatar Dec 02 '24 06:12 juangon

Thanks @benedikt-bartscher , but how can I use rx.asset inside a CSS file?

You can't, maybe there is a way to set the frontend root in package.json and let react adjust all those paths instead? My pr is just a draft for rx.asset support, not a full fix for this

benedikt-bartscher avatar Dec 02 '24 21:12 benedikt-bartscher

We do have some path rewriting here https://github.com/reflex-dev/reflex/blob/a320d062fb739235642c95fc4907f7d5f9531e44/reflex/.templates/web/jsconfig.json#L5-L6, but i think this applies only to js files, not to css.

masenf avatar Dec 02 '24 21:12 masenf

Assets path should add FRONTEND_PATH to the referenced resources.

I don't know if this is generally achievable while still making it possible to access files from the root of the host ("above" where the reflex app is served)

masenf avatar Dec 02 '24 21:12 masenf

From my point of view, as I would like to "detach" the needed configuration from testing (ie., all localhost and root path) to production (proxy and URL that uses paths to serve different services). I would like having DEPLOY_URL variable as the path that reflex adds to every relative path within the application. I think FRONTEND_PATH and DEPLOY_URL sounds a bit duplicate for the same stuff maybe.

juangon avatar Dec 03 '24 07:12 juangon