fix(SW-2603): Images from API are now served through the Netlify image CDN.
Approved-by: Linus Flood
This commit is contained in:
@@ -6,25 +6,15 @@ import type { CSSProperties } from "react"
|
|||||||
|
|
||||||
import type { ImageProps } from "@/types/components/image"
|
import type { ImageProps } from "@/types/components/image"
|
||||||
|
|
||||||
function isBlockedByFirewall(src: string): boolean {
|
|
||||||
return (
|
|
||||||
src.includes("test.scandichotels.com") ||
|
|
||||||
src.includes("test2.scandichotels.com") ||
|
|
||||||
src.includes("test3.scandichotels.com") ||
|
|
||||||
src.includes("stage.scandichotels.com") ||
|
|
||||||
src.includes("prod.scandichotels.com")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function imageLoader({ quality, src, width }: ImageLoaderProps) {
|
function imageLoader({ quality, src, width }: ImageLoaderProps) {
|
||||||
const isAbsoluteUrl = src.startsWith("https://") || src.startsWith("http://")
|
const isAbsoluteUrl = src.startsWith("https://") || src.startsWith("http://")
|
||||||
const hasQS = src.indexOf("?") !== -1
|
const hasQS = src.indexOf("?") !== -1
|
||||||
|
|
||||||
if (!isAbsoluteUrl || isBlockedByFirewall(src)) {
|
if (isAbsoluteUrl) {
|
||||||
return `${src}${hasQS ? "&" : "?"}w=${width}${quality ? "&q=" + quality : ""}`
|
return `https://img.scandichotels.com/.netlify/images?url=${src}&w=${width}${quality ? "&q=" + quality : ""}`
|
||||||
}
|
}
|
||||||
|
|
||||||
return `https://img.scandichotels.com/.netlify/images?url=${src}&w=${width}${quality ? "&q=" + quality : ""}`
|
return `${src}${hasQS ? "&" : "?"}w=${width}${quality ? "&q=" + quality : ""}`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next/Image adds & instead of ? before the params
|
// Next/Image adds & instead of ? before the params
|
||||||
|
|||||||
Reference in New Issue
Block a user