Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sveltekit example #297

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions packages/blob/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,15 @@ export async function list(
}

function getApiUrl(pathname = ''): string {
const baseUrl =
process.env.VERCEL_BLOB_API_URL ||
process.env.NEXT_PUBLIC_VERCEL_BLOB_API_URL ||
'https://blob.vercel-storage.com';

return `${baseUrl}${pathname}`;
let baseUrl = null;
try {
// wrapping this code in a try/catch as this function is used in the browser and Vite doesn't define the process.env.
// As this varaible is NOT used in production, it will always default to production endpoint
baseUrl =
process.env.VERCEL_BLOB_API_URL ||
process.env.NEXT_PUBLIC_VERCEL_BLOB_API_URL;
} catch {}
return `${baseUrl || 'https://blob.vercel-storage.com'}${pathname}`;
}

function mapBlobResult(blobResult: HeadBlobApiResponse): HeadBlobResult;
Expand Down Expand Up @@ -324,7 +327,13 @@ function shouldFetchClientToken(
}

function getApiVersionHeader(): { 'x-api-version'?: string } {
const versionOverride = process.env.VERCEL_BLOB_API_VERSION_OVERRIDE;
let versionOverride = null;
try {
// wrapping this code in a try/catch as this function is used in the browser and Vite doesn't define the process.env.
// As this varaible is NOT used in production, it will always default to the BLOB_API_VERSION
versionOverride = process.env.VERCEL_BLOB_API_VERSION_OVERRIDE ||
process.env.NEXT_PUBLIC_VERCEL_BLOB_API_VERSION_OVERRIDE;
} catch {}

return {
'x-api-version': `${versionOverride ?? BLOB_API_VERSION}`,
Expand Down
Loading