Can I set the media url in the config.php?

I’m trying to integrate a CDN to Kirby for all my static files, including media files. I see here that to load the media files from other than the default location, I have to put the path in the index.php but to do that I’d have to hardcode the CDN path in the file. What’s more, I only want to load them from CDN in production not in dev.

Anytime I try to load anything from the config in index.php it breaks the site
I’ve tried (new Kirby)->option('cdn.path') or require __DIR__ . '/site/config/config.php' I just get an error

Argument 1 passed to Kirby\Cms\App::extendHooks() must be of the type array, bool given, called in /XXX/kirby/src/Cms/AppPlugins.php on line 99

How can I conditionally load the media path in index.php? And if I can’t, can I configure the global media url path in config.php so I don’t have to mess with the index file?

This unpublished recipe might help: https://github.com/getkirby/getkirby.com/pull/899/files

It was postponed because the devs wanted to make this easier somehow, and there were some changes to components, so maybe I should get back to it.