Access-Control-Allow-Origin problem

Hi everyone, I’m having a problem when I try to read from the blockchain. Sometimes I get this error: header CORS Access-Control-Allow-Origin is missing. This happen when I read from the blockchain with the PureStake credentials. But the strange think is that this problem don’t show up every time, but only sometimes. If i try to refresh the page is possible that the next execution goes all ok without problem, or is possible that I receive again the error. How can I resolve this problem? I’m using Laravel and Heroku. The problem is present if I run the site on localhost and if I run the site on Heroku.

Thanks, :slight_smile:

Hey - shoot me a note letting me know which call (endpoint) you are making when that happens. I suspect one of the error responses is not properly configured.

Hi Tim,
I hope that you can help me. I receive this error on the browser console:

how did you resolve this ?

The main issue here was calling a v2 path with a v1 client or vice versa. We added a sample HTML file that declares a v1, v2, and Indexer client to our API samples repo.

A snippet:

    const legacyServer  = "https://testnet-algorand.api.purestake.io/ps1";
    const newServer     = "https://testnet-algorand.api.purestake.io/ps2";
    const indexServer   = "https://testnet-algorand.api.purestake.io/idx2";
    const port          = "";
    const token         = { 'X-API-key' : 'YOUR KEY HERE'}

    let algodClient     = new algosdk.Algod(token, legacyServer, port);
    let algodClientV2   = new algosdk.Algodv2(token, newServer, port);
    let indexerClient   = new algosdk.Indexer(token, indexServer, port);

Hi!

I’m using v2 client with v2 server. It works when calling status and account/{account} endpoints. But getting CORS error for assets:

https://testnet-algorand.api.purestake.io/ps2/v2/assets/{asset-id}

Need to add anything specific for assets?

could you please paste the output of a curl -v with both of the URLs so that we could see the returned HTTP headers ?

Thanks for the quick reply!

The thing is that I’m testing from browser using JS SDK… this code was working by running the local node. But now I see that assets api from purestake is not going with Algod, but from indexer. Thus main url is different and querying assets didn’t work.

Hi @pagito,

It’s perfectly fine that you’re testing it from within the browser. In that case, try to open the browser developer console and looks for the response headers for the above request, and (maybe) compare it with the one you would get from the node directly.

( if you were to have this issue on one of the other SDKs, I would suggest trying Wireshark… )

If you could identify which headers are missing, it would be extremely helpful.

thanks!

I think this is resolved? All asset endpoints are in Indexer now and use the /idx2 path and not /ps2 which @pagito mentions.

Correct @Tim I would be happy to help on identifying the problem @tsachi . But in this case, I think there is no issue, as I was trying to use /ps2 for asset endpoints. Which later I saw is going through Indexer.

Although, I guess the response should be 404 instead of displaying CORS error?

It is true, the error is incorrect! I have a ticket to fix it and will revisit.