From 44dd81504250db917188f3d4f0ec845cef246998 Mon Sep 17 00:00:00 2001 From: Xi Xu Date: Tue, 25 Nov 2025 18:07:20 +0800 Subject: [PATCH] Improve environment detection in sync workflow Enhanced the handler to better distinguish between Netlify, Vercel, and other environments. Environment variable normalization now accounts for different runtime contexts, and warning logs for unsupported features are always shown, not just in non-production. --- .github/workflows/sync.yml | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 35cdf56..526b5b4 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -258,9 +258,21 @@ jobs: export default async function handler(request, context) { // Detect runtime environment const isNetlify = context && (context.geo !== undefined || context.ip !== undefined); + const isVercel = !isNetlify && context; // Normalize environment variables - const envSource = isNetlify && context.env ? context.env : process.env; + // Netlify provides context.env, Vercel Edge uses globalThis + let envSource; + if (isNetlify) { + envSource = context.env || {}; + } else if (typeof process !== 'undefined' && process.env) { + // Vercel or Node.js environment + envSource = process.env; + } else { + // Fallback for other environments + envSource = {}; + } + const env = { TIMEOUT_SECONDS: envSource.TIMEOUT_SECONDS, MAX_RETRIES: envSource.MAX_RETRIES, @@ -278,15 +290,11 @@ jobs: : (promise) => { // No-op on Vercel: background tasks not supported // Cache writes will run synchronously instead - if (process.env.NODE_ENV !== 'production') { - console.warn('waitUntil is not supported in Vercel Edge Runtime'); - } + console.warn('waitUntil is not supported in Vercel Edge Runtime'); }, passThroughOnException: () => { // Not supported on either platform in this context - if (process.env.NODE_ENV !== 'production') { - console.warn('passThroughOnException is not universally supported'); - } + console.warn('passThroughOnException is not universally supported'); } };