diff options
author | 2023-07-17 20:57:08 +0800 | |
---|---|---|
committer | 2023-07-17 20:57:08 +0800 | |
commit | 1c8a225a5bdde57a9f1abf8a517ae2c583e4652b (patch) | |
tree | 87572535e6a3a48e8ca4bccb0e594aacdcbfc681 | |
parent | fcd23b4c56244fcd966828edeae288a66910bf9f (diff) | |
download | astro-1c8a225a5bdde57a9f1abf8a517ae2c583e4652b.tar.gz astro-1c8a225a5bdde57a9f1abf8a517ae2c583e4652b.tar.zst astro-1c8a225a5bdde57a9f1abf8a517ae2c583e4652b.zip |
Fix cloudflare runtime env var handling (#7679)
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
Co-authored-by: Matthew Phillips <matthew@skypack.dev>
-rw-r--r-- | packages/integrations/cloudflare/src/index.ts | 8 | ||||
-rw-r--r-- | packages/integrations/cloudflare/test/basics.test.js | 2 |
2 files changed, 9 insertions, 1 deletions
diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index fa064e0ac..40ee006f3 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -91,6 +91,14 @@ export default function createIntegration(args?: Options): AstroIntegration { } vite.ssr ||= {}; vite.ssr.target = 'webworker'; + + // Cloudflare env is only available per request. This isn't feasible for code that access env vars + // in a global way, so we shim their access as `process.env.*`. We will populate `process.env` later + // in its fetch handler. + vite.define = { + 'process.env': 'process.env', + ...vite.define, + }; } }, 'astro:build:ssr': ({ entryPoints }) => { diff --git a/packages/integrations/cloudflare/test/basics.test.js b/packages/integrations/cloudflare/test/basics.test.js index b97079b8f..9aa78f98e 100644 --- a/packages/integrations/cloudflare/test/basics.test.js +++ b/packages/integrations/cloudflare/test/basics.test.js @@ -2,7 +2,7 @@ import { loadFixture, runCLI } from './test-utils.js'; import { expect } from 'chai'; import * as cheerio from 'cheerio'; -describe.skip('Basic app', () => { +describe('Basic app', () => { /** @type {import('./test-utils').Fixture} */ let fixture; /** @type {import('./test-utils').WranglerCLI} */ |