how to solve CORS Policy for bot testing

Hello team, i am trying to deploy a bot localy, to test some design changes for the interface, i have followed the guide for setting everything up, but when i try to run the bot localy, i get this error:
Access to XMLHttpRequest at ‘localhost:8545/api/users/sts’ from origin ‘http://localhost:8545’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

I understand i have to make some changes, which i have done, but its still not working, the changes i have made are the following:

At the users.js file i addded :

res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Headers', 'Authorization, X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Allow-Request-Method');
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE');
res.header('Allow', 'GET, POST, OPTIONS, PUT, DELETE');

Thanks in advance for your help

1 Like

Hi @gabriel.garcia,

I understand you have created a local server for running JWT service (on 8545 port) and trying to refer that service from your web sdk.

Solution: Try to use ‘cors’ npm module (if Node JS or equivalent in other languages) to suppress this error in your servers code.

I also recommend to use a public tunnel instead of localhost. You can quickly create by using ‘ngrok’ service.

Regards,
Karthik

to use that module, i just need to install it as i ran the npm install? do you have any extra docs where i could research more about this?

Yes. You can refer to https://www.npmjs.com/package/cors