Streamline remote patterns in next.config.js

This commit is contained in:
Sam Becker 2023-11-26 20:38:33 -06:00
parent be5d389b20
commit f321bc775c

View File

@ -1,6 +1,7 @@
const VERCEL_BLOB_STORE_ID = process.env.BLOB_READ_WRITE_TOKEN?.match(
/^vercel_blob_rw_([a-z0-9]+)_[a-z0-9]+$/i,
)?.[1].toLowerCase();
const VERCEL_BLOB_HOSTNAME = VERCEL_BLOB_STORE_ID
? `${VERCEL_BLOB_STORE_ID}.public.blob.vercel-storage.com`
: undefined;
@ -12,23 +13,22 @@ const AWS_S3_HOSTNAME =
? `${process.env.NEXT_PUBLIC_S3_BUCKET}.s3.${process.env.NEXT_PUBLIC_S3_REGION}.amazonaws.com`
: undefined;
const createRemotePattern = (hostname) => hostname
? {
protocol: 'https',
hostname,
port: '',
pathname: '/**',
}
: [];
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
imageSizes: [200],
remotePatterns: []
.concat(VERCEL_BLOB_HOSTNAME ? {
protocol: 'https',
hostname: VERCEL_BLOB_HOSTNAME,
port: '',
pathname: '/**',
} : [])
.concat(AWS_S3_HOSTNAME ? {
protocol: 'https',
hostname: AWS_S3_HOSTNAME,
port: '',
pathname: '/**',
} : []),
.concat(createRemotePattern(VERCEL_BLOB_HOSTNAME))
.concat(createRemotePattern(AWS_S3_HOSTNAME)),
minimumCacheTTL: 31536000,
},
};