SolidJSS
SolidJS13mo ago
5 replies
Jason.json

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:

function baseUrl(): string {
  if (production()) return prodServer;
  return devServer;
}


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?
Was this page helpful?