Skip to content

Commit

Permalink
fix: revert #12227 (#12351)
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-lefebvre authored Nov 1, 2024
1 parent c480b8f commit 5751488
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-radios-live.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion packages/astro/src/env/runtime-constants.ts

This file was deleted.

6 changes: 1 addition & 5 deletions packages/astro/src/env/runtime.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
7 changes: 5 additions & 2 deletions packages/astro/src/env/vite-plugin-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5751488

Please sign in to comment.