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);