FooSoft / anki-connect

Anki plugin to expose a remote API for creating flash cards.
https://foosoft.net/projects/anki-connect/
Other
1.92k stars 218 forks source link

Cors error. Using Anki 2.1.49. #372

Open joaquintoral opened 1 year ago

joaquintoral commented 1 year ago

I'm getting this error

Access to XMLHttpRequest at 'http://localhost:8765/' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'http://localhost' that is not equal to the supplied origin.

This is what my anki-connect config.js looks like

{ "apiKey": null, "apiLogPath": null, "ignoreOriginList": [], "webBindAddress": "127.0.0.1", "webBindPort": 8765, "webCorsOrigin": "http://localhost", "webCorsOriginList": [ "http://localhost", null ] }

I've been experimenting on this for the whole day, but I can't seem to figure out why Anki still won't allow me to pull data from Anki Connect.

andreaskienle commented 1 year ago

Can you try adding "http://localhost:3000" and/or "http://localhost:8765" to the webCorsOriginList array?

{ "apiKey": null, "apiLogPath": null, "ignoreOriginList": [], "webBindAddress": "127.0.0.1", "webBindPort": 8765, "webCorsOrigin": "http://localhost", "webCorsOriginList": [ "http://localhost", null, "http://localhost:8765", "http://localhost:3000"] }

joaquintoral commented 1 year ago

Can you try adding "http://localhost:3000" and/or "http://localhost:8765" to the webCorsOriginList array?

{ "apiKey": null, "apiLogPath": null, "ignoreOriginList": [], "webBindAddress": "127.0.0.1", "webBindPort": 8765, "webCorsOrigin": "http://localhost", "webCorsOriginList": [ "http://localhost", null, "http://localhost:8765", "http://localhost:3000"] }

I did try that. But it didn't work. I had to edit the add-on code and add the URLs there instead.

andreaskienle commented 1 year ago

Ok, that's weird. For me this always does the trick.