Access-Control-Allow-Origin

Hi,

I am trying to connect to my Coronium Cloud server from another server, I am getting NO Access-Control-Allow-Origin error in the browser.

Is there a way to config Access-Control-Allow-Origin to accept connections from my second server?

Thanks

Rui

Hi,

I’m afraid I don’t really have an answer for you, as that is a non-standard way of using Coronium.

Cheers.

Thanks for the prompt reply…

If you want to do this in pure javascript you will want to research CORS. Here is a stackoverflow post that can get you started http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy. It is not a trivial setup and will require some NGINX configuration.

 

My suggestion however is to have your javascript make a call to your web-server and then have the web-server make the call to your Coronium server. This would be similar to what I suggested here https://forums.coronalabs.com/topic/63624-read-sql-database-from-a-webpage/ for exposing MySql.

 

Pros:

  1. You should not experience the CORS issue as the browser is calling a script on your web-server domain
  2. You will not expose your API credentials in the browser
  3. This is typically easier to debug

Cons:

  1. Your web-server now has to help with the processing - should not be a big deal
  2. If you have high latency it will be compounded - again this should not be an issue and if so is more than likely something another problem you should fix. 

Hi Steven,

Thanks for your time, really appreciated,

Great answer, help me a lot, now I understand that CORS thing,

Take care,

Rui

Hi,

I’m afraid I don’t really have an answer for you, as that is a non-standard way of using Coronium.

Cheers.

Thanks for the prompt reply…

If you want to do this in pure javascript you will want to research CORS. Here is a stackoverflow post that can get you started http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy. It is not a trivial setup and will require some NGINX configuration.

 

My suggestion however is to have your javascript make a call to your web-server and then have the web-server make the call to your Coronium server. This would be similar to what I suggested here https://forums.coronalabs.com/topic/63624-read-sql-database-from-a-webpage/ for exposing MySql.

 

Pros:

  1. You should not experience the CORS issue as the browser is calling a script on your web-server domain
  2. You will not expose your API credentials in the browser
  3. This is typically easier to debug

Cons:

  1. Your web-server now has to help with the processing - should not be a big deal
  2. If you have high latency it will be compounded - again this should not be an issue and if so is more than likely something another problem you should fix. 

Hi Steven,

Thanks for your time, really appreciated,

Great answer, help me a lot, now I understand that CORS thing,

Take care,

Rui