App is only working inside of development store

Shopify Partner
13 0 0

Hi,

My app imports a script tag into the store that it's downloaded on and inside of that script it makes an ajax call to my app's server which is obviously on a different domain. I'm able to run the app on my development stores without any problems but I just downloaded it on a regular store (non-dev) and inside of the browser console I get the following error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://1e61ca69.ngrok.io/shop/1. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

Is there something different between a dev store and a regular store that could be causing this and how can I fix it?

My app is created with ROR and I already have the following header set inside of application.rb:

      'Access-Control-Allow-Origin' => '*',

Thank you!

0 Likes
Shopify Partner
27 0 2

Hi Kolby,

I faced similar issue regarding Cross orgin request block. Shopify won't easily allow the cross origin request.

Few things to consider:

1. Your request domain should have SSL installed i.e the url should be in https.

2. In your AJAX request include crossDomain:true and async:true. see example below:

jQuery.ajax({
          method:'GET',
          url: "https://your-appdomain.com/method",
          crossDomain: true,
          async:true,
          dataType: 'json',
          data:{ code: value },
          beforeSend: function(){
            //use this if required
          },
          success: function(data){
          //use this for success callback
         
          },
          complete: function(dataa) { 
           //use this if required
          }
        });

 

I solved mine with this. Try considering above points if you haven't already and improvise as per your requirement.

Hope it helps!!

Regards,

Navin

0 Likes
Shopify Partner
13 0 0

Hi Navin!

Thank you for the reply. Funny enough I'm actually working on the issue right now and I almost have it fixed. I switched over to using JSONP instead and so far it looks like it's going to work.

0 Likes
Highlighted
Shopify Partner
27 0 2

Great!! 

Good to hear that.

0 Likes