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

Fix server-side rendering for App Bridge v4 #1327

Merged
merged 2 commits into from
Aug 21, 2024

Conversation

paulomarg
Copy link
Collaborator

@paulomarg paulomarg commented May 6, 2024

WHY are these changes introduced?

As part of updating the template to use App Bridge React v4, we'll need to include the api key in the index.html file, which is served by the backend of the app.

Vite will handle replacing it in client-side renders, which is why the variable needs to start with a VITE_.

WHAT is this pull request doing?

Dynamically replacing the api key when serving that file.

@paulomarg paulomarg requested a review from a team as a code owner May 6, 2024 17:56
.send(
readFileSync(join(STATIC_PATH, "index.html"))
.toString()
.replace("%VITE_SHOPIFY_API_KEY%", process.env.SHOPIFY_API_KEY || "")
Copy link

Choose a reason for hiding this comment

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

instead of replacing string like this, can we use the define config for SHOPIFY_API_KEY like

define: {
  'import.meta.env.SHOPIFY_API_KEY': process.env.SHOPIFY_API_KEY
}

Copy link
Collaborator Author

@paulomarg paulomarg May 7, 2024

Choose a reason for hiding this comment

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

No, that's we had before, but it only affects the pages that vite builds - this call is rendering the file in the server for the initial page load.

The problem is that this value needs to be set by the time the FE loads, so replacing it there is too late.

@paulomarg paulomarg force-pushed the app_bridge_v4_replace_api_key branch from 97aff25 to 4028bfe Compare August 14, 2024 19:39
@paulomarg paulomarg changed the title [WIP] Fix server-side rendering for App Bridge v4 Fix server-side rendering for App Bridge v4 Aug 14, 2024
@paulomarg paulomarg requested a review from sle-c August 14, 2024 19:41
Copy link

@matteodepalo matteodepalo left a comment

Choose a reason for hiding this comment

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

LGTM!

@paulomarg paulomarg merged commit 864edba into main Aug 21, 2024
9 checks passed
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.

3 participants