0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00
This commit is contained in:
Florian Lefebvre 2024-11-01 16:53:15 +01:00 committed by GitHub
parent c480b8f2c4
commit 5751488165
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 11 additions and 8 deletions

View file

@ -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

View file

@ -1 +0,0 @@
export const ENV_SYMBOL = Symbol.for('astro:env/dev');

View file

@ -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;

View file

@ -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,