user3226932
user3226932

Reputation: 2252

using regex for image domains in NextJS next.config.js

does regex work in next.config.js for image domains? Looks like giphy uses different numbers for its endpoints (e.g. media0.giphy.com, media2.giphy.com) but regex isn't working so I'm getting this error: hostname "media0.giphy.com" is not configured under images in your next.config.js. If not, is there a good way to handle this?

next.config.js:

const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  images: {
    dangerouslyAllowSVG: true,
    domains: ["media\\d.giphy.com"],
  },
};

Upvotes: 1

Views: 1126

Answers (1)

Konrad
Konrad

Reputation: 24671

No, domains don't support regex. Use remotePatterns which support glob (similar to regex).

Domains

Similar to remotePatterns, the domains configuration can be used to provide a list of allowed hostnames for external images.

However, the domains configuration does not support wildcard pattern matching and it cannot restrict protocol, port, or pathname.

Note: We recommend using remotePatterns instead so you can restrict protocol and pathname.

Upvotes: 3

Related Questions