Changing baseURL based on production and window.location.href
I have an API calling function that builds URLs like this: ${baseUrl()}/api/[...].
The baseUrl function looks like this:
However, when testing the production build, it uses
prodServer
, which is my domain, but the API calls fail because the connection is refused from localhost.
I tried checking window.location.href to see if it includes devServer
or prodServer
, but this doesn’t work as expected. Many API calls are created in server-side code where window is undefined.
Is there a better way to determine the URL context in such cases?3 Replies
Perhaps: https://discord.com/channels/722131463138705510/1320826293654261822/1320893327419248743
look also at the earlier posts.
Note though the certain vite configuration options won't work right now though I'm expecting more to become available once the most recent vite/nitro/vinxi reorganization comes to a close.
GitHub
How to do conditional vite config depending on mode (i.e. dev or pr...
In pre-beta2, we can still use this https://vitejs.dev/config/#conditional-config where defineConfig can accept a function that has mode that determine development or production. However in beta-2,...
I didn't looked at them sorry
But thanks anyway
For your help