Skip to content

Commit 70bd4b6

Browse files
committed
NEX-195: Simplify remotePatterns generation in next.config.mjs
1 parent 339c79a commit 70bd4b6

File tree

1 file changed

+12
-30
lines changed

1 file changed

+12
-30
lines changed

next/next.config.mjs

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,6 @@ import createNextIntlPlugin from "next-intl/plugin";
55

66
const withNextIntl = createNextIntlPlugin();
77

8-
const imageHostnameInternal = String(
9-
process.env.DRUPAL_BASE_URL_INTERNAL_IMAGES,
10-
).split("://");
11-
12-
if (imageHostnameInternal.length < 2) {
13-
throw new Error(
14-
"Invalid DRUPAL_BASE_URL_INTERNAL_IMAGES. Expected a valid URL with protocol and hostname.",
15-
);
16-
}
17-
18-
const imageHostnameExternal = String(
19-
process.env.NEXT_PUBLIC_DRUPAL_BASE_URL,
20-
).split("://");
21-
22-
if (imageHostnameExternal.length < 2) {
23-
throw new Error(
24-
"Invalid NEXT_PUBLIC_DRUPAL_BASE_URL. Expected a valid URL with protocol and hostname.",
25-
);
26-
}
27-
288
/** @type {import('next').NextConfig} */
299
const nextConfig = {
3010
reactStrictMode: true,
@@ -40,17 +20,19 @@ const nextConfig = {
4020

4121
images: {
4222
remotePatterns: [
43-
{
44-
protocol: imageHostnameExternal[0] === "https" ? "https" : "http",
45-
hostname: imageHostnameExternal[1],
23+
process.env.DRUPAL_BASE_URL_INTERNAL_IMAGES,
24+
process.env.NEXT_PUBLIC_DRUPAL_BASE_URL,
25+
].map((url = "") => {
26+
const [protocol, hostname] = url.split("://");
27+
if (!hostname || (protocol !== "https" && protocol !== "http")) {
28+
throw new Error(`Invalid images URL "${url}" in next.config.ts`);
29+
}
30+
return {
31+
protocol,
32+
hostname,
4633
pathname: "**",
47-
},
48-
{
49-
protocol: imageHostnameInternal[0] === "https" ? "https" : "http",
50-
hostname: imageHostnameInternal[1],
51-
pathname: "**",
52-
},
53-
],
34+
};
35+
}),
5436
},
5537

5638
experimental: {

0 commit comments

Comments
 (0)