mirror of
https://github.com/withastro/astro.git
synced 2025-01-06 22:10:10 -05:00
parent
c480b8f2c4
commit
5751488165
4 changed files with 11 additions and 8 deletions
.changeset
packages/astro/src/env
5
.changeset/friendly-radios-live.md
Normal file
5
.changeset/friendly-radios-live.md
Normal 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
|
1
packages/astro/src/env/runtime-constants.ts
vendored
1
packages/astro/src/env/runtime-constants.ts
vendored
|
@ -1 +0,0 @@
|
|||
export const ENV_SYMBOL = Symbol.for('astro:env/dev');
|
6
packages/astro/src/env/runtime.ts
vendored
6
packages/astro/src/env/runtime.ts
vendored
|
@ -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;
|
||||
|
|
7
packages/astro/src/env/vite-plugin-env.ts
vendored
7
packages/astro/src/env/vite-plugin-env.ts
vendored
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue