Configure remote_images for dev vs. prod

  • We use Convex, a hosted DB, which gives each dev their own hosted dev DB.
  • Uploaded images are served from our DB instances, like https://foo-instances.convex.cloud/images/1234

I want to add a different remote_path for the Netlify Image CDN in local dev vs. in production but cannot figure out how.

  • I wrote a build plugin with both onPreDev and onPreBuild that writes .netlify/deploy/v1/config.json based on the “CDN Integration” doc, but that file does not seem to be read in local development?
  • The remote URL is an environment variable configured in Netlify’s UI and in .env.local for local development
  • Doesn’t appear possible to reference an environment variable inside netlify.toml

How can I change the image CDN in dev vs. prod and have it be based off a environment variable?

Why not simply add all the remote URLs that you’d end up using? You can add the dev as well as prod values in there. Not sure why it needs to be per environment. Could you clarify if I’m missing something?

Thank you for the response.

Each developer gets their own remote DB instance. It would be cumbersome to add/remove remote URLs as engineers work on the project and at a large enough team size it would be untenable. It’s also not 100% correct because we don’t want our prod app to be loading images from dev DB instances.

Sections like [[headers]] and [[redirects]] are able to replace values at build time with sed, but the images config has already been read at that point. I am hoping to do a similar replacement in the [images] block.

Yes, but unless you use your dev URLs in the prod instance, that won’t happen. As long as you don’t end up adding dev URLs in your prod instance, simply having the extra URLs in the netlify.toml won’t make a difference.

I don’t believe this would be an issue unless each dev is getting absolutely random URLs. As long as they have a pattern, you can use a RegEx, for example:

https:\/\/[a-z]*-instances\.convex\.cloud\/images\/.*

Even if everyone gets a random URL, like I mentioned, it would be a one-time add (or remove) and won’t have to be done repeatedly.

It’s currently not supported, but we can add a feature request. Though, based on the above workarounds, I believe the priority for this would be very low.

I ended up adding all convex.cloud URLs, which is not ideal but works. What happens to our bandwidth usage if someone else uses our production Netlify instance to point to URLs on Convex instances we don’t own? That was my concern with allowing all subdomains.

I’m sorry, I’m not sure if I understand this question. Could you try rephrasing it?

Because I added all *.convex.cloud URLs to the allowlist you can presumably use our Netlify app to point to any public Convex instance - even ones we don’t own or control.

What happens to our Netlify usage if someone uses our production Netlify Image CDN URLs to point to Convex instances that aren’t ours? Is Image CDN usage a billable feature of Netlify?

# our fake website
https://foo.com 

# our fake Convex instance
https://good.convex.cloud

# bad actor's fake Convex instance
https://bad.convex.cloud

# bad actor's use of our Netlify
https://foo.com/.netlify/images?url=https://bad.convex.cloud/abc