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 entrypoint #248

Open
mbrodala opened this issue Jan 4, 2021 · 2 comments
Open

Dynamic entrypoint #248

mbrodala opened this issue Jan 4, 2021 · 2 comments

Comments

@mbrodala
Copy link
Contributor

mbrodala commented Jan 4, 2021

Description
There should be an option to have a dynamic entrypoint when generating client code.

Currently the API endpoint passed to the generator is also used as entrypoint. This is not optimal:

  1. A development setup may be accessed differently via CLI and via web (e.g. using internal service host names and public URLs in a Docker Compose setup)
  2. Different environments need different host names, hardcoding one will break requests.

Example
Running the generator with http://apache/api/ will generate all code and lead to exactly this being set in config/entrypoint.js. Now accessing http://app.local/<resource> will fail since apache is a host name internally resolved in a Docker Compose setup while the setup is accessed via app.local from the host machine.

Currently we work around this by adjusting entrypoint.js like this after generating the code:

export const ENTRYPOINT = `${location.protocol}//${location.host}/api/`;

Maybe this or similar could be integrated for dynamic entrypoints.

@alOneh
Copy link
Contributor

alOneh commented Jan 5, 2021

Hi @mbrodala, thanks for reporting this issue.
As the entrypoint.js file is generated once, I think we should let people implements their own logic in this file to retrieve the right value for this variable.
Personally, in my project, I prefer using a dot env file containing the right value for the different environments I use.

When you generate your code for the first time you can use the env API_PLATFORM_CLIENT_GENERATOR_ENTRYPOINT to set the correct value of your entrypoint if it helps.

https://github.com/api-platform/client-generator/blob/b1b89e8acec69b2483ad366161564ebaaa2b61ac/src/index.js#L46-L55

@mbrodala
Copy link
Contributor Author

mbrodala commented Jan 5, 2021

Yeah, I noticed the support for environment variables. But this wouldn't really help in our case since the API is accessed differently via CLI and web as mentioned.

Also my impression so far is that I should be able to drop the generated code at any time and re-generate it to get the latest updates/fixes from the templates of this package. This currently requires me to override the entrypoint.js after each re-generation.

Using .env is a possible solution but needs to be taken into account when deploying to an environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants