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

[WIP] Fix server-side rendering for App Bridge v4 #1327

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

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.

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.

None yet

2 participants