Get a peek at our latest innovations at Sanity Product Day on Dec 8th →

How to Set CORs Origins for Cloudflare Pages

7 replies
Last updated: May 3, 2022

Hey y’all - I’m wondering if there is a way to set CORs origins for cloudflare pages deploy previews with a URL pattern like this

https://{hash}.domain.pages.dev
where the hash is unique for each PR. Here’s an example from the project we’re working on:
https://444238b5.stylitics-demo-beta.pages.dev

May 3, 2022, 9:22 PM

If I’m understanding right you should be able to do it like this:

https://*.<http://domain.pages.dev|domain.pages.dev>

May 3, 2022, 9:25 PM

I’ve tried that and get this err

May 3, 2022, 9:29 PM

That’s really weird, just tested and it worked for me

May 3, 2022, 9:38 PM

Very weird indeed!

May 3, 2022, 9:39 PM

It’s a browser thing (this will work in Chrome but not Firefox). Jacob: Please try in Chrome or using the CLI (

sanity cors add https://*.<http://stylitics-demo-beta.pages.dev|stylitics-demo-beta.pages.dev> --no-credentials
). Apologies for the inconvenience.

May 3, 2022, 10:25 PM

Oh damn! Maybe this will be the nail in the coffin for me leaving FF haha

May 3, 2022, 10:27 PM

Worked like a charm - thanks

user A
!

May 3, 2022, 10:28 PM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Free to get started, and pay-as-you-go on all plans. Find out more.