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

🔧Runtime config for the frontend #345

Merged
merged 4 commits into from
Aug 21, 2024
Merged

🔧Runtime config for the frontend #345

merged 4 commits into from
Aug 21, 2024

Conversation

AntoLC
Copy link
Collaborator

@AntoLC AntoLC commented Aug 20, 2024

Purpose

We want to be able to pass environment variables at runtime to the frontend.

To do so, we created a public endpoint on the backend to share some configurations.
The frontend will get the conf, then adapt itself depend of them.

In this case we wanted to hide the teams feature but only for the production environments (preprod, production).

Proposal

  • ✨(backend) add public endpoint /api/v1.0/config/
  • ✨(frontend) add config provider
  • ♻️(frontend) replace env NEXT_PUBLIC_FEATURE_TEAM
  • 🔧(helm) deactivate teams feature on productions env
  • tests

Demo

scrnli_8_20_2024_12-35-34.PM.webm

Add public endpoint /api/v1.0/config/ to
share some public configuration values
with the frontend.
@AntoLC AntoLC added frontend Relative to the frontend backend helm feature labels Aug 20, 2024
@AntoLC AntoLC self-assigned this Aug 20, 2024
@AntoLC AntoLC changed the title 🔧Frontend env config 🔧Runtime config for the frontend Aug 20, 2024
Add a ConfigProvider to the frontend to provide
configuration to the app.
The configuration is loaded from the config
endpoint and stored in a zustand store.
@AntoLC AntoLC force-pushed the feature/front-env-config branch 2 times, most recently from 84b7319 to 966f798 Compare August 20, 2024 10:26
@AntoLC AntoLC marked this pull request as ready for review August 20, 2024 10:26
NEXT_PUBLIC_FEATURE_TEAM is a buid-time env
variable, it is not easy to overload it per
environment.
We will use the config endpoint to get the
feature flag at runtime.
To do so, we are using the ConfigStore.
Teams feature is not ready for production yet,
so we need to deactivate it on productions environment.
preprod should be a copy of production,
so we need to deactivate it on preprod too.
Comment on lines +33 to +35
useConfigStore.setState({
config: { FEATURES: { TEAMS: false }, LANGUAGES: [] },
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌🏾 good design pattern to isolate the front-end from external behaviors like these from the back-end.

Copy link
Collaborator

@sdemagny sdemagny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nickel !

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