CORS error for server requests [SOLVED]

Hi All,

The scenario is, I want to use the rasa nlu server with my react application. My react application runs on port 3000 and I am running rasa nlu server on port 5002.

I am following this guide to run the server: Server Configuration

While testing with postman application, nlu apis are working fine. But while doing the same api requests from the react application, it is failing.

The error I am facing while sending request: xhr.js?14ed:178 OPTIONS http://localhost:5002/parse 403 (Forbidden) Access to XMLHttpRequest at ‘http://localhost:5002/parse’ from origin ‘http://localhost:3000’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

I tried a lot to fix this issue with --cors argument, but still, it is not working and still showing the same errors again and again. Probably I am not understanding how to use the cors argument properly.

Can anyone tell me how to fix it? It will be a great help since there are no proper answers out there on how to use cors arguments on any website. Let me know if anyone needs more information on this.

Best Regards, Abhishek C

1 Like

can you show the command you are using to run the rasa core server?

and make sure you had had --enable_api & --cors “*”

Hi Jitesh, Currently, I am running the rasa nlu server with --cors “*” argument (I think --enable_api is only for rasa core)

The command I am executing to spin the server:

python -m rasa_nlu.server -c config.yaml --pre_load model_1 --path venv/models/nlu/ -P 5002 --cors “*”

hey @abhic7 if you dont mind can you run the above command without using the port argument?

Still the same error :frowning:

@JiteshGaikwad

Thanks for your help man! :slight_smile:

I figured out the issue. It is because of the server.js of rasa nlu. Unfortunately, cross-origin and header support are not there. After editing the server.js file, I am now able to execute cross origin requests.

For more information, please check this github issue:

1 Like

Not an issue anymore as the required code is now merged with master branch.

I am still getting this error. All help appreciated

thanks

1 Like

im using rasa run -m models --enable-api --cors “*” but still getting this error Access to XMLHttpRequest at ‘http://localhost:5005/socket.io/?EIO=3&transport=polling&t=Mt1DGKX’ from origin ‘null’ has been blocked by CORS policy: The ‘Access-Control-Allow-Origin’ header contains multiple values ‘null, null’, but only one is allowed.

The endpoint which you are trying to hit is used for Socket

Check this Your Own Website

Actually I’m trying to integrate the website using webchat only and in the integration there seems a problem. Can you help to fix this error so my bot can be used from a website.

Ya sure which webchat u r trying to integrate?

Do we need any more addition of files or code to add in above webchat?

Hi @ashishPatel, sorry for the late reply, you need to just register socket channel in your config.yml file

Currently this is my content of config.yml Can you tell me what should I add in this file

Hey @ashishPatel sorry I said wrong it was credentials.yml file

Oh kk here is credentials file

What should I add…?

ya this what we need, this should work