Blocked by CORS policy request from mydomain.myshopify.com to mydomain.com

From one day to another We’ve receiving this CORS policy error.

We’ve not made any recent changes to our store, but it appears the theme’s code is fetching urls with the “myshopify.com” domain instead of our default domain.

Is there any way we can achieve to use entirely our default domain?

this is an example:

Access to XMLHttpRequest at ‘https://mydomainname.myshopify.com/search?view=ajax-article-page&type=article,page&q=salmon*’ from origin ‘https://mydomainname.com’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

Of course, but it would be necessary to see your store and the code which generates the message to suggest anything.

1 Like

The issue is in several js calls to cart.js, search and other pages within the theme.

I’ve found That routes.search_URL is getting myshopify.com domain instead of my default domain.

As I’ve been reading there is no way to change that on the theme settings

Hope you can help me, thanks in advance

That’s suspicious – routes use relative paths and do not include domain name.

Must be something in your theme code, most probably in layouts/theme.liquid where all these variables are defined for JS use.

If you afraid of sharing your store URL, you can DM it to me.

1 Like

@tim_1 Helped us a lot to find the cause of the problem, it was not the theme’s code.

After viewing the homepage tags he identified the document.baseURI was mydomainname.myshopify.com

Later we found out that when creating a blog post the same way as usual (we don’t know why), in the Excerpt of the post, an html tag was added

so this base tag changed all our homepage baseURI to the shopify domain generating the CORS error.

Thanks again to @tim_1 for helping us to solve this issue that seemed to be imposible

Hi, I’m having the same issue with CORs errors, seemingly all of a sudden, across several pages. I found your post and the cause appears to be the same, as I can see the wrong URL being entered with a tag on my pages that point to the mydomain.myshopify.com instead of mydomain. The part I’m not understanding is the resolution, as I can’t find where this value is being set. Can you possibly share more details as to how you resolved the issue? Thanks a lot.

In our scenario, the <base… tag was inserted when a blog post was created.

On the blog post creation There’s an “Excerpt” section that allows you to see the code when clicking the "</>"button.

there we found certain blog posts with the myshopify url instead the domain name.

You can open your browser web tools and find the url to see in which part of the code it is inserted so you could look for it in a mor targeted way

Share your store URL

Found it, thanks. Not sure how it happened, but for others it appears that a page being updated inserted the base href tag (down at the bottom where the edits were made, only visible when viewing the source obviously). Not sure why that was added given similar/earlier edits didn’t add an href tag, but that was definitely the cause and removing it resolved the issue. Thanks again.

Hi Tim I saw you were able to help someone on this issue. I was hoping if you could help me aswell.

I think im having the exact same issue except the weird thing is i have a script that changes the site to /nl (Dutch language) and with the /nl the problem does not accur but with the original mydomain it does.

i already tried deleting the language script in hopes it would work but it did not.

url morretz.com