56 lines
1.2 KiB
TypeScript
56 lines
1.2 KiB
TypeScript
import type { NextConfig } from "next";
|
|
|
|
type ImageRemotePattern = NonNullable<NonNullable<NextConfig["images"]>["remotePatterns"]>[number];
|
|
|
|
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
|
const assetRemotePatterns = (process.env.NEXT_PUBLIC_CERASUS_ASSET_HOSTS || "")
|
|
.split(",")
|
|
.map((host) => toAssetRemotePattern(host))
|
|
.filter((pattern): pattern is ImageRemotePattern => Boolean(pattern));
|
|
|
|
const nextConfig: NextConfig = {
|
|
output: "export",
|
|
...(basePath ? { basePath } : {}),
|
|
images: {
|
|
unoptimized: true,
|
|
...(assetRemotePatterns.length
|
|
? {
|
|
remotePatterns: assetRemotePatterns,
|
|
}
|
|
: {}),
|
|
},
|
|
poweredByHeader: false,
|
|
turbopack: {
|
|
root: process.cwd(),
|
|
},
|
|
devIndicators: false,
|
|
};
|
|
|
|
export default nextConfig;
|
|
|
|
function toAssetRemotePattern(
|
|
value: string,
|
|
): ImageRemotePattern | undefined {
|
|
const input = value.trim();
|
|
|
|
if (!input) {
|
|
return undefined;
|
|
}
|
|
|
|
try {
|
|
const url = new URL(input.includes("://") ? input : `https://${input}`);
|
|
|
|
if (url.protocol !== "https:" || !url.hostname) {
|
|
return undefined;
|
|
}
|
|
|
|
return {
|
|
protocol: "https",
|
|
hostname: url.hostname,
|
|
...(url.port ? { port: url.port } : {}),
|
|
};
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
}
|