assetPrefix like in NextJS #9784
Unanswered
RafalFilipek
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
TLDR;
Is there any way to prefix all generated URLs in app in development and production mode so all URLs like:
are served as:
I'll handle rewrite of those URLs in my proxy server.
Full story:
Currently, my monorepo consists solely of Next.JS-based applications. This makes it relatively easy to manage. My developer proxy server is running on port 3000. I have a mapping of paths that each application handles, for example:
Serving multiple NextJS applications under one domain is straightforward using the
assetPrefix
option, which allows adding a prefix to all assets loaded on the page. This mechanism works in both development and production mode. Thus, each application has a unique prefix set, such as/app1-static/
. Therefore, when I load the page http://localhost:3000/foo/bar, I know that the traffic should go to theapp1
application. The HTML returned by this application contains links with the appropriate prefix, which also allows me to serve files through the corresponding NextJS instance (proxy server handles logic regarding rewriting URLs etc, so target app can handle normal URL).Challenges with Remix (or Vite)
Unfortunately, Remix does not have such an option. Various issues, documentation, etc., refer to two keys:
base
and setting thebasename
in the Remix plugin.Unfortunately, they relate more to the address at which the application is available. I don't want to change the base path for my application or anything like that.
The lack of the ability to set a prefix for static files in development mode makes it (almost) impossible to correctly route traffic after loading the initial code.
My current workaround is filthy; on reverse proxy server I'm enhancing specific responses (from initial requests like HTML code) with extra cookie
current_app
. All subsequent requests on a given page are using cookies value to route the given URL to the proper upstream app.Thank you in advance for any help and comments
Rafał
Beta Was this translation helpful? Give feedback.
All reactions