forked from jsnbuchanan/crowd-funder-for-time-pwa
Fix image CORS violations with comprehensive proxy and component updates
- Applied transformImageUrlForCors to all image-displaying components - Added followRedirects: true to image proxy to serve actual content - Proxy now returns 200 OK with image data instead of 301 redirects - Maintains CORS headers required for SharedArrayBuffer support - Added debug logging for proxy response monitoring Resolves all image loading failures in development environment.
This commit is contained in:
@@ -926,3 +926,40 @@ export async function importFromMnemonic(
|
||||
// Save the new identity
|
||||
await saveNewIdentity(newId, mne, derivationPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms direct image URLs to use proxy endpoints in development to avoid CORS issues
|
||||
* with restrictive headers required for SharedArrayBuffer support.
|
||||
*
|
||||
* @param imageUrl - The original image URL
|
||||
* @returns Transformed URL that uses proxy in development, original URL otherwise
|
||||
*
|
||||
* @example
|
||||
* transformImageUrlForCors('https://image.timesafari.app/abc123.jpg')
|
||||
* // Returns: '/image-proxy/abc123.jpg' in development
|
||||
* // Returns: 'https://image.timesafari.app/abc123.jpg' in production
|
||||
*/
|
||||
export function transformImageUrlForCors(
|
||||
imageUrl: string | undefined | null,
|
||||
): string {
|
||||
if (!imageUrl) return "";
|
||||
|
||||
// Only transform in development mode
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
return imageUrl;
|
||||
}
|
||||
|
||||
// Transform direct image.timesafari.app URLs to use proxy
|
||||
if (imageUrl.startsWith("https://image.timesafari.app/")) {
|
||||
const imagePath = imageUrl.replace("https://image.timesafari.app/", "");
|
||||
return `/image-proxy/${imagePath}`;
|
||||
}
|
||||
|
||||
// Transform other timesafari.app subdomains if needed
|
||||
if (imageUrl.includes(".timesafari.app/")) {
|
||||
const imagePath = imageUrl.split(".timesafari.app/")[1];
|
||||
return `/image-proxy/${imagePath}`;
|
||||
}
|
||||
|
||||
return imageUrl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user