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

config: Fetch config from server in frontend #609

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tahini
Copy link
Collaborator

@tahini tahini commented Mar 20, 2023

Instead of having it built into the application at webpack time, it is fetched at load time from the server.

This adds an express route named /config that returns a Status with the project configuration.

The client's entry page now needs to asynchronously fetch it from server using this route and the page is only rendered when the response is back. If there is an error while getting the configuration, the MaintenancePage is displayed.

@tahini tahini force-pushed the refactorPreferences branch 2 times, most recently from c5ef595 to 522e620 Compare March 27, 2023 16:52
@tahini tahini force-pushed the refactorPreferences branch 2 times, most recently from a17c33d to 6b2b8fd Compare March 29, 2023 19:45
Instead of having it built into the application at webpack time, it is
fetched at load time from the server.

This adds an express route named `/config` that returns a Status with
the project configuration.

The client's entry page now needs to asynchronously fetch it from server
using this route and the page is only rendered when the response is
back. If there is an error while getting the configuration, the
MaintenancePage is displayed.

Because the initial frontend configuration is now asynchronous at the
application start, the i18n.config is converted to a function, which
initializes the i18n object that should be called once the configuration
is fetched.
greenscientist
greenscientist previously approved these changes May 17, 2023
Copy link
Collaborator

@greenscientist greenscientist left a comment

Choose a reason for hiding this comment

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

I had comments that maybe need fixing, but approving since they might be ok.

@@ -7,3 +7,4 @@
export { default as LoadingPage } from './LoadingPage';
export * from './NotFoundPage';
export { default as LoginPage } from './LoginPage';
export { default as MaintenancePage } from './MaintenancePage';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this change relevant?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it allows to import the MaintenancePage along with the rest instead of a separate import.

Copy link
Collaborator

@greenscientist greenscientist May 18, 2023

Choose a reason for hiding this comment

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

ok, missread as import instead of export

hasConfig = configOk;
renderApp();
});

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we have a catch or a else to catch (and log) failure here?

Copy link
Collaborator Author

@tahini tahini left a comment

Choose a reason for hiding this comment

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

Thanks for approving the direction, but I think this can still be improved. Especially that the application "entry" will have to be updated in Evolution also. I'll dismiss your review for now so it doesn't accidentally gets merged and I'll try to make it better soon.

@@ -7,3 +7,4 @@
export { default as LoadingPage } from './LoadingPage';
export * from './NotFoundPage';
export { default as LoginPage } from './LoginPage';
export { default as MaintenancePage } from './MaintenancePage';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it allows to import the MaintenancePage along with the rest instead of a separate import.

const renderApp = () => {
if (!hasRendered) {
ReactDOM.render(jsx, document.getElementById('app'));
if (!hasRendered && hasConfig !== undefined && hasFetchedAuth !== undefined) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In retrospect, 2 things I don't like here: the multiple flags and the fact that we need to call a i18n initialization function. It makes the currentLanguage potentially undefined and multiplies the possibilities. I think we should fetch the configuration, then import the rest which we are certain will run with a valid configuration. If we can't get the config, we put a [eventually] pretty and generic failure page.

@tahini tahini dismissed greenscientist’s stale review May 18, 2023 02:49

Not ready for merge yet, still can be improved

@tahini
Copy link
Collaborator Author

tahini commented May 18, 2023

I'll work on #54 first

@tahini tahini marked this pull request as draft October 27, 2023 16:33
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

Successfully merging this pull request may close these issues.

2 participants