From f2d03ebec675736ee1da3bcb8f21b9536ab7af0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20FAMIBELLE-PRONZOLA?= Date: Fri, 26 Jun 2026 00:33:54 +0400 Subject: [PATCH] feat: parse image domains from NEXT_PUBLIC_DOMAINS_IMAGE --- next.config.js | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/next.config.js b/next.config.js index 8332286..dbfcaa9 100644 --- a/next.config.js +++ b/next.config.js @@ -5,6 +5,22 @@ const withPWA = require('next-pwa')({ skipWaiting: true }) +function buildRemotePatterns() { + const raw = process.env.NEXT_PUBLIC_DOMAINS_IMAGE || '' + const patterns = raw.split(' ').filter(Boolean).map(entry => { + const [hostname, port] = entry.split(':') + const isLocal = hostname === 'localhost' || hostname === '127.0.0.1' + const pattern = {protocol: isLocal ? 'http' : 'https', hostname, pathname: '/uploads/**'} + if (port) pattern.port = port + return pattern + }) + if (!raw.includes('localhost')) + patterns.push({protocol: 'http', hostname: 'localhost', port: '1337', pathname: '/uploads/**'}) + if (!raw.includes('127.0.0.1')) + patterns.push({protocol: 'http', hostname: '127.0.0.1', port: '1337', pathname: '/uploads/**'}) + return patterns +} + module.exports = (withPWA({ turbopack: {}, webpack: config => { @@ -16,29 +32,6 @@ module.exports = (withPWA({ return config }, images: { - remotePatterns: [ - { - protocol: 'https', - hostname: 'api.pawol.nu', - pathname: '/uploads/**', - }, - { - protocol: 'https', - hostname: 'pawol.nu', - }, - { - protocol: 'http', - hostname: '127.0.0.1', - port: '1337', - pathname: '/uploads/**', - }, - { - protocol: 'http', - hostname: 'localhost', - port: '1337', - pathname: '/uploads/**', - }, - ] - + remotePatterns: buildRemotePatterns() } }))