Solved

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

UBAUTISTA
Shopify Partner
3 1 0

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.

Accepted Solution (1)

UBAUTISTA
Shopify Partner
3 1 0

This is an accepted solution.

@tim 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

<base href = "mydomainname.myshopify.com"/>

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

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

View solution in original post

Replies 4 (4)

tim
Shopify Expert
3464 280 1285

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

 

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com
UBAUTISTA
Shopify Partner
3 1 0

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

tim
Shopify Expert
3464 280 1285

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.

 

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com

UBAUTISTA
Shopify Partner
3 1 0

This is an accepted solution.

@tim 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

<base href = "mydomainname.myshopify.com"/>

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

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