diff --git a/.changeset/friendly-radios-live.md b/.changeset/friendly-radios-live.md new file mode 100644 index 0000000000..723a3d7f83 --- /dev/null +++ b/.changeset/friendly-radios-live.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Reverts a change made in `4.16.6` that prevented usage of `astro:env` secrets inside middleware in SSR diff --git a/packages/astro/src/env/runtime-constants.ts b/packages/astro/src/env/runtime-constants.ts deleted file mode 100644 index 27b5d72113..0000000000 --- a/packages/astro/src/env/runtime-constants.ts +++ /dev/null @@ -1 +0,0 @@ -export const ENV_SYMBOL = Symbol.for('astro:env/dev'); diff --git a/packages/astro/src/env/runtime.ts b/packages/astro/src/env/runtime.ts index 50684f63ef..a2017b617f 100644 --- a/packages/astro/src/env/runtime.ts +++ b/packages/astro/src/env/runtime.ts @@ -1,16 +1,12 @@ import { AstroError, AstroErrorData } from '../core/errors/index.js'; import { invalidVariablesToError } from './errors.js'; -import { ENV_SYMBOL } from './runtime-constants.js'; import type { ValidationResultInvalid } from './validators.js'; export { validateEnvVariable, getEnvFieldType } from './validators.js'; export type GetEnv = (key: string) => string | undefined; type OnSetGetEnv = (reset: boolean) => void; -let _getEnv: GetEnv = (key) => { - const env = (globalThis as any)[ENV_SYMBOL] ?? {}; - return env[key]; -}; +let _getEnv: GetEnv = (key) => process.env[key]; export function setGetEnv(fn: GetEnv, reset = false) { _getEnv = fn; diff --git a/packages/astro/src/env/vite-plugin-env.ts b/packages/astro/src/env/vite-plugin-env.ts index a672addccd..06d5b047c9 100644 --- a/packages/astro/src/env/vite-plugin-env.ts +++ b/packages/astro/src/env/vite-plugin-env.ts @@ -9,7 +9,6 @@ import { VIRTUAL_MODULES_IDS_VALUES, } from './constants.js'; import { type InvalidVariable, invalidVariablesToError } from './errors.js'; -import { ENV_SYMBOL } from './runtime-constants.js'; import type { EnvSchema } from './schema.js'; import { getEnvFieldType, validateEnvVariable } from './validators.js'; @@ -42,7 +41,11 @@ export function astroEnv({ fileURLToPath(settings.config.root), '', ); - (globalThis as any)[ENV_SYMBOL] = loadedEnv; + for (const [key, value] of Object.entries(loadedEnv)) { + if (value !== undefined) { + process.env[key] = value; + } + } const validatedVariables = validatePublicVariables({ schema,