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:
1 parent
0e7aad4755
commit
44dd815042
1 file changed
+13
-5
@@ -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,16 +290,12 @@ 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');
|
||||
}
|
||||
},
|
||||
passThroughOnException: () => {
|
||||
// Not supported on either platform in this context
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.warn('passThroughOnException is not universally supported');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Delegate to the main request handler
|
||||
|
||||
Reference in new issue
Block a user