Replies: 13 comments 10 replies
-
I came across to the same need. Have you found any other solutions? I'd like serve this way nextjs exported app. |
Beta Was this translation helpful? Give feedback.
-
Hey, manually adding the basepath to different parts of the code was getting dirty and not working properly in later versions so removed it and went with the standard way of adding it as a build variable. To solve my issue with the docker images I now build two different images each with a different basePath. This doesn't scale at all for more basePaths but for now have only needed these 2. |
Beta Was this translation helpful? Give feedback.
-
Has anyone come up with a way of doing something like this at runtime? I have a basePath use case as well, surprising that there's no way to provide runtime context. |
Beta Was this translation helpful? Give feedback.
-
Hi all, I have a "workaround" for this based off @apotdevin answer . But I'd really love the community to tell me I'm making a big mistake (or making too many assumptions).
This feels "safe" for now, but I worry that there may be a later breaking change hidden in the roadmap. |
Beta Was this translation helpful? Give feedback.
-
Hi again, this is a current issue if you want to deploy multi tenant projects. Currently we're exploring the following with next
Definitely feels fragile, and we're exploring the consequences. For now the big hit, by looking at
|
Beta Was this translation helpful? Give feedback.
-
any update? |
Beta Was this translation helpful? Give feedback.
-
In the meantime: use env variables - here's what worked for me:
basePath: process.env.NEXT_PUBLIC_BASE_PATH, Now anywhere else in your Next JS app, you can access the base path using |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I would love to see the answer for this question. I am facing an issue that I have to build an docker image and run it in multiple docker images with different basePath and assetPrefix. |
Beta Was this translation helpful? Give feedback.
-
We need to be able to easily switch basePath via ENV var at runtime. I shouldn't have to have this var exposed during build time |
Beta Was this translation helpful? Give feedback.
-
My Solution
Keep Smiling 😊 |
Beta Was this translation helpful? Give feedback.
-
I did this in
|
Beta Was this translation helpful? Give feedback.
-
Ran into this too which was a hard requirement for our distributed Docker image where end-users are not expected to build the Next.js app from scratch and require providing config via environment variables (12-factor-app) To sidestep Next.js' weird fake environment variable string-replacement, I use The script is injected here: https://github.com/Southclaws/storyden/blob/main/web/src/app/layout.tsx#L21-L31 One caveat here though: this script is not loaded when Next.js encounters an error or a not-found (so, loading error.tsx or not-found.tsx) so if you rely on API calls for error reporting, it would require yet another workaround. For the backend side, we provide an isometric helper to get the config: https://github.com/Southclaws/storyden/blob/main/web/src/config.ts It also might be possible to use instrumentation-client.js file convention: https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation-client I've not yet confirmed is this also works for error.tsx or not-found.tsx Hope this helps! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Seeing that version 9.5 had the customizable base path out of the box I updated my project but started encountering various problems.
First it's a build variable so after creating a docker image, it can no longer be changed thus removing this customization option for any user that downloads the project's docker image.
After seeing this problem, I went back to how I had it setup before:
basePath
aspublicRuntimeConfig
in thenext.config.js
Link
, the public assetsrc
and the routerpush
and left the nextjs version at 9.5.
Wanted to see if anyone is having a similar issue? Maybe there's a better way to handle the basePath as a runtime variable that I'm missing on this last version?
Beta Was this translation helpful? Give feedback.
All reactions