CORS wildcard subdomain not working with Netlify domain

4 replies
Last updated: Jul 14, 2021
hi, i’m having trouble adding a CORS origin with a wildcard to a new project. When i enter
https://*<http://my-project-name.netlify.app|my-project-name.netlify.app>
I get an error: “Unable to parse URL”. I’ve been able to successfully do this in the past (to target Netlify branch deploys)
AI Update

I can see you're getting the "Unable to parse URL" error when trying to add a wildcard CORS origin for your Netlify branch deploys. Good news - Sanity does support wildcard CORS origins, but the format needs to be exact.

Based on the official Sanity CORS documentation, wildcards (*) are allowed in CORS origins. For Netlify branch deploys, the correct format should be:

https://*.my-project-name.netlify.app

Note the placement: https://* followed directly by .your-domain (no space, no extra characters).

Troubleshooting Your "Unable to parse URL" Error

If you're entering the wildcard correctly and still getting this error, here are some things to check:

  1. Remove any extra spaces - Make sure there are no leading or trailing spaces in the URL field
  2. Verify the protocol - Must be https:// (not http://)
  3. Check for special characters - The error message you showed has some formatting that suggests there might be extra characters. Make sure you're entering just: https://*.my-project-name.netlify.app
  4. Try a specific URL first - Test with a concrete branch deploy URL like https://main--my-project-name.netlify.app to verify your project settings are working

How to Add CORS Origins

You can configure CORS origins in two ways:

Via Management Dashboard:

  1. Go to manage.sanity.io
  2. Select your project
  3. Navigate to Settings > API > CORS Origins
  4. Add your wildcard origin: https://*.my-project-name.netlify.app
  5. Enable "Allow credentials" if you're using authentication tokens with the Sanity client

Via Sanity CLI:

sanity cors add https://*.my-project-name.netlify.app --credentials

If the dashboard is giving you trouble, try the CLI method as an alternative.

Netlify-Specific Considerations

Netlify branch deploys use the pattern https://branch-name--site-name.netlify.app, so the wildcard https://*.my-project-name.netlify.app should cover all your branch deploys perfectly.

Don't forget to also add http://localhost:3000 (or your local dev port) for local development work.

If you're still encountering the parsing error after verifying the format, there may be a temporary issue with the Management Dashboard. In that case, definitely try the CLI method or reach out to Sanity support through the Community Slack for direct assistance.

Show original thread
4 replies
Hi Patrick. This might be one you’ll need to add from the command line. Could you please try
sanity cors add <URL>
from your terminal?
thanks
user A
that worked
fair enough to warn users on that level! 😄
Thanks Patrick. I’ll pass along the feedback. 👍

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?