Image loader exclude blocked domains
This commit is contained in:
@@ -7,12 +7,29 @@ import type { CSSProperties } from "react"
|
|||||||
|
|
||||||
import type { ImageProps } from "@/types/components/image"
|
import type { ImageProps } from "@/types/components/image"
|
||||||
|
|
||||||
|
const isBlockedByFirewall = (src: string) => {
|
||||||
|
if (
|
||||||
|
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")
|
||||||
|
) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
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) {
|
if (isAbsoluteUrl) {
|
||||||
return `https://image-scandic-hotels.netlify.app/.netlify/images?url=${src}&w=${width}${quality ? "&q=" + quality : ""}`
|
if (isBlockedByFirewall(src)) {
|
||||||
|
return `${src}${hasQS ? "&" : "?"}w=${width}${quality ? "&q=" + quality : ""}`
|
||||||
|
} else {
|
||||||
|
return `https://img.scandichotels.com/.netlify/images?url=${src}&w=${width}${quality ? "&q=" + quality : ""}`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${src}${hasQS ? "&" : "?"}w=${width}${quality ? "&q=" + quality : ""}`
|
return `${src}${hasQS ? "&" : "?"}w=${width}${quality ? "&q=" + quality : ""}`
|
||||||
|
|||||||
@@ -43,10 +43,6 @@ const nextConfig = {
|
|||||||
protocol: "https",
|
protocol: "https",
|
||||||
hostname: "*.scandichotels.com",
|
hostname: "*.scandichotels.com",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
protocol: "https",
|
|
||||||
hostname: "image-scandic-hotels.netlify.app",
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user