From b68bfa8d5e2c214659a4e1d7c67b6c3f8b9111c0 Mon Sep 17 00:00:00 2001 From: Linus Flood Date: Thu, 31 Oct 2024 08:23:20 +0100 Subject: [PATCH] Image loader exclude blocked domains --- components/Image.tsx | 19 ++++++++++++++++++- next.config.js | 4 ---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/components/Image.tsx b/components/Image.tsx index a5ea6e16a..44c2ca662 100644 --- a/components/Image.tsx +++ b/components/Image.tsx @@ -7,12 +7,29 @@ import type { CSSProperties } from "react" 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) { const isAbsoluteUrl = src.startsWith("https://") || src.startsWith("http://") const hasQS = src.indexOf("?") !== -1 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 : ""}` diff --git a/next.config.js b/next.config.js index d8e14a2f8..2e8553f1c 100644 --- a/next.config.js +++ b/next.config.js @@ -43,10 +43,6 @@ const nextConfig = { protocol: "https", hostname: "*.scandichotels.com", }, - { - protocol: "https", - hostname: "image-scandic-hotels.netlify.app", - }, ], },