Skip to content

Commit

Permalink
Handle case where cache-control causes CORS issues
Browse files Browse the repository at this point in the history
  • Loading branch information
PrafulB committed Jan 23, 2024
1 parent 46d40d8 commit e6d425f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 7 additions & 4 deletions imagebox3.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,14 @@ var imagebox3 = (() => {
return response
}

const getImagesInPyramid = async (imageID) => {
const getImagesInPyramid = async (imageID, cache=true) => {
// Get all images in the pyramid.

tiff[imageID] = tiff[imageID] || {}

try {

tiff[imageID].pyramid = tiff[imageID].pyramid || ( await GeoTIFF.fromUrl(imageID, { headers: {'Cache-Control': "no-cache, no-store"}}) )
const headers = cache ? { headers: {'Cache-Control': "no-cache, no-store"}} : {}
tiff[imageID].pyramid = tiff[imageID].pyramid || ( await GeoTIFF.fromUrl(imageID, headers) )

const imageCount = await tiff[imageID].pyramid.getImageCount()
if (tiff[imageID].pyramid.loadedCount !== imageCount) {
Expand All @@ -242,7 +242,10 @@ var imagebox3 = (() => {
}

} catch (e) {
console.error("Couldn't get images", e)
console.error("Couldn't get images", e)
if (cache) { // Retry in case Cache-Control is not part of Access-Control-Allow-Headers in preflight response
await getImagesInPyramid(imageID, !cache)
}
}
return
}
Expand Down
11 changes: 7 additions & 4 deletions imagebox3.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,14 @@ const imagebox3 = (() => {
return response
}

const getImagesInPyramid = async (imageID) => {
const getImagesInPyramid = async (imageID, cache=true) => {
// Get all images in the pyramid.

tiff[imageID] = tiff[imageID] || {}

try {

tiff[imageID].pyramid = tiff[imageID].pyramid || ( await fromUrl(imageID, { headers: {'Cache-Control': "no-cache, no-store"}}) )
const headers = cache ? { headers: {'Cache-Control': "no-cache, no-store"}} : {}
tiff[imageID].pyramid = tiff[imageID].pyramid || ( await fromUrl(imageID, headers) )

const imageCount = await tiff[imageID].pyramid.getImageCount()
if (tiff[imageID].pyramid.loadedCount !== imageCount) {
Expand All @@ -221,7 +221,10 @@ const imagebox3 = (() => {
}

} catch (e) {
console.error("Couldn't get images", e)
console.error("Couldn't get images", e)
if (cache) { // Retry in case Cache-Control is not part of Access-Control-Allow-Headers in preflight response
await getImagesInPyramid(imageID, !cache)
}
}
return
}
Expand Down

0 comments on commit e6d425f

Please sign in to comment.