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
I tried checking window.location.href to see if it includes
Is there a better way to determine the URL context in such cases?
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?
