CORS Error: No 'Access-Control-Allow-Origin' Header

Hello everyone,

I’ve recently deployed my web app on the Internet Computer, but I’m encountering the following error:

Screenshot from 2024-05-29 18-04-36

I’m wondering if this error could be related to the following line of code in my application:

const agent = new HttpAgent({ host: ‘https://icp0.io’ });

Could this be causing the issue? If so, how can I resolve it?

Any help would be greatly appreciated. Thank you!

Hey can you send your code?

Hey @krunal,

You should not be using mainnet.dfinity.network for API calls, but icp-api.io. Did you come across it in some documentation?

my code seems to be making an API request implicitly, and I can’t figure out which part of it is responsible.

Check the code that is triggered when clicking the “Log in” button.

const whitelist = [process.env.CANISTER_ID];
const host = “https://mainnet.dfinity.network”;
await window.ic.plug.requestConnect({ whitelist, host });

In official documentation of plug wallet they have provided code as above.i have wrote the same.
i think this is causing problem.

so i have to modify it like below, right ?

const host = “https://icp-api.io

Yep, that change should fix your issue. Unfortunately the Plug docs seems to be outdated.