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.
This commit is contained in:
xixu-me committed 2025-11-25 18:07:20 +08:00
1 parent 0e7aad4755
commit 44dd815042
1 file changed
+15 -7
+15 -7
View File
@@ -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');
}
};