Skip to content

Commit

Permalink
[remix] Set default env vars for Hydrogen v2 deployments (vercel#10341)
Browse files Browse the repository at this point in the history
In order to make the default mock shop created from `npm create @shopify/hydrogen@latest` work out-of-the-box and without additional configuration, set the necessary default environment variables to make the server not render an error.
  • Loading branch information
TooTallNate authored Aug 15, 2023
1 parent ae20c72 commit 844fb6e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-pens-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vercel/remix-builder': patch
---

Set default env vars for Hydrogen v2 deployments
15 changes: 14 additions & 1 deletion packages/remix/src/hydrogen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,22 @@ export function patchHydrogenServer(
.join(', ')}) ${fetchMethod.getBody()!.getText()}`;
defaultExportSymbol.replaceWithText(newFunction);

const defaultEnvVars = {
SESSION_SECRET: 'foobar',
PUBLIC_STORE_DOMAIN: 'mock.shop',
};
const envCode = `const env = { ${envProperties
.map(name => `${name}: process.env.${name}`)
.join(', ')} };`;
.join(', ')} };\n${Object.entries(defaultEnvVars)
.map(
([k, v]) =>
`if (!env.${k}) { env.${k} = ${JSON.stringify(
v
)}; console.warn('Warning: ${JSON.stringify(
k
)} env var not set - using default value ${JSON.stringify(v)}'); }`
)
.join('\n')}`;

const updatedCodeString = sourceFile.getFullText();
return `${envCode}\n${updatedCodeString}`;
Expand Down
12 changes: 0 additions & 12 deletions packages/remix/test/fixtures/10-hydrogen-2/vercel.json

This file was deleted.

12 changes: 0 additions & 12 deletions packages/remix/test/fixtures/11-hydrogen-2-js/vercel.json

This file was deleted.

0 comments on commit 844fb6e

Please sign in to comment.