Corregge l'accesso all'env Worker per Astro 6.
Sostituisce locals.runtime.env con import da cloudflare:workers, ripristinando contatti e newsletter. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
/**
|
||||
* Shared helpers for newsletter API routes (Cloudflare Worker / Astro).
|
||||
*/
|
||||
import { env as workerEnv } from 'cloudflare:workers';
|
||||
|
||||
export type RuntimeEnv = Record<string, unknown>;
|
||||
|
||||
@ -19,20 +20,9 @@ export type NewsletterSubscriber = {
|
||||
unsubscribed_at: string | null;
|
||||
};
|
||||
|
||||
export function getRuntimeEnv(locals: unknown): RuntimeEnv {
|
||||
if (
|
||||
locals &&
|
||||
typeof locals === 'object' &&
|
||||
'runtime' in locals &&
|
||||
locals.runtime &&
|
||||
typeof locals.runtime === 'object' &&
|
||||
'env' in locals.runtime &&
|
||||
locals.runtime.env &&
|
||||
typeof locals.runtime.env === 'object'
|
||||
) {
|
||||
return locals.runtime.env as RuntimeEnv;
|
||||
}
|
||||
return {};
|
||||
/** Astro v6+: use `cloudflare:workers` env (locals.runtime.env was removed). */
|
||||
export function getRuntimeEnv(_locals?: unknown): RuntimeEnv {
|
||||
return workerEnv as unknown as RuntimeEnv;
|
||||
}
|
||||
|
||||
export function readEnv(name: string, runtimeEnv: RuntimeEnv): string {
|
||||
|
||||
Reference in New Issue
Block a user