Skip to content
Open
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: 21 additions & 2 deletions packages/storage-vercel-blob/src/staticHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,32 @@ export const getStaticHandler = (
},
})

if (!response.ok || !response.body) {
// If CDN fetch fails, try downloadUrl from head() as fallback
let finalResponse = response
if (!response.ok) {
const fallbackResponse = await fetch(blobMetadata.downloadUrl, {
headers: {
'Cache-Control': 'no-store, no-cache, must-revalidate',
Pragma: 'no-cache',
...(rangeResult.type === 'partial' && {
Range: `bytes=${rangeResult.rangeStart}-${rangeResult.rangeEnd}`,
}),
},
})
if (fallbackResponse.ok) {
finalResponse = fallbackResponse
} else {
return new Response(null, { status: 502, statusText: 'Bad Gateway' })
}
}

if (!finalResponse.body) {
return new Response(null, { status: 204, statusText: 'No Content' })
}

headers.append('Last-Modified', uploadedAtString)

return new Response(response.body, {
return new Response(finalResponse.body, {
headers,
status: rangeResult.status,
})
Expand Down
Loading