diff --git a/.changeset/spicy-hotels-argue.md b/.changeset/spicy-hotels-argue.md new file mode 100644 index 000000000..d49e50324 --- /dev/null +++ b/.changeset/spicy-hotels-argue.md @@ -0,0 +1,5 @@ +--- +"@vercel/blob": patch +--- + +chore(blob): Allow using the alternative API. No new feature, no bugfix here. diff --git a/packages/blob/src/api.ts b/packages/blob/src/api.ts index c909aaf19..d634977ac 100644 --- a/packages/blob/src/api.ts +++ b/packages/blob/src/api.ts @@ -186,6 +186,7 @@ export async function requestApi( ): Promise { const apiVersion = getApiVersion(); const token = getTokenFromOptionsOrEnv(commandOptions); + const extraHeaders = getProxyThroughAlternativeApiHeaderFromEnv(); const apiResponse = await retry( async (bail) => { @@ -198,7 +199,7 @@ export async function requestApi( headers: { 'x-api-version': apiVersion, authorization: `Bearer ${token}`, - + ...extraHeaders, ...init.headers, }, }); @@ -241,3 +242,27 @@ export async function requestApi( return (await apiResponse.json()) as TResponse; } + +function getProxyThroughAlternativeApiHeaderFromEnv(): { + 'x-proxy-through-alternative-api'?: string; +} { + const extraHeaders: Record = {}; + + try { + if ('VERCEL_BLOB_PROXY_THROUGH_ALTERNATIVE_API' in process.env) { + extraHeaders['x-proxy-through-alternative-api'] = + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- we know it's here from the if + process.env.VERCEL_BLOB_PROXY_THROUGH_ALTERNATIVE_API!; + } else if ( + 'NEXT_PUBLIC_VERCEL_BLOB_PROXY_THROUGH_ALTERNATIVE_API' in process.env + ) { + extraHeaders['x-proxy-through-alternative-api'] = + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- we know it's here from the if + process.env.NEXT_PUBLIC_VERCEL_BLOB_PROXY_THROUGH_ALTERNATIVE_API!; + } + } catch { + // noop + } + + return extraHeaders; +}