Trouble with Programmatically Updating Media URLS in API to Cloudfront domain URL

I read about middleware and again just tried to just wing it