Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic base url using env vars #90

Closed
nopitown opened this issue Apr 24, 2024 · 4 comments · Fixed by #88
Closed

Dynamic base url using env vars #90

nopitown opened this issue Apr 24, 2024 · 4 comments · Fixed by #88
Labels
question Further information is requested

Comments

@nopitown
Copy link
Sponsor

Is your feature request related to a problem? Please describe.
Currently, I'm unable to use a dynamic base for the URLs. In production webs, urls might differ from those in dev environments. I saw that we have a --base option, but it seems that only a string can be sent.

Describe the solution you'd like
Make --base more flexible so it can also accept env vars. This is currently possible if we modify the OpenAPI config

Describe alternatives you've considered
I also considered using the new interceptor feature, but it isn't possible to modify the URL.

Additional context
This feature would be really good in order to be able to prefetch queries in server components as fetch calls doesn't accept relative paths.

@seriouslag
Copy link
Collaborator

seriouslag commented Apr 24, 2024

@nopitown,

Modifying the OpenAPI config sounds precisely like what you need.

Changing the BASE URL option on the OpenAPI config.

Import the constant into your runtime and modify it before setting up the react app.

/** main.tsx */
import { OpenAPI as OpenAPIConfig } from './openapi/requests/core/OpenAPI';
...
OpenAPIConfig.BASE = 'www.domain.com/api';
...
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
  <React.StrictMode>
    <QueryClientProvider client={queryClient}>
      <App />
    </QueryClientProvider>
  </React.StrictMode>
);

@nopitown
Copy link
Sponsor Author

Oh! I didn't know I was able to override it like that. I'll try it out!

@seriouslag seriouslag added the question Further information is requested label Apr 24, 2024
@nopitown
Copy link
Sponsor Author

It does work as expected! I guess it is just a matter to document it in a FAQ. Thank you so much for the help!

@seriouslag
Copy link
Collaborator

Opened PR #88 to add info in readme.

@7nohe 7nohe closed this as completed in #88 Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants