tauri-apps / tauri-invoke-http

A custom invoke system for Tauri that leverages a localhost server
Apache License 2.0
48 stars 5 forks source link

cors #13

Closed dtdyq closed 11 months ago

dtdyq commented 11 months ago

Access to XMLHttpRequest at 'http://localhost:23486/main' from origin 'http://localhost:1420' 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.

metruzanca commented 11 months ago

I am also getting this. Heres my setup: https://github.com/metruzanca/quantframe

Access to XMLHttpRequest at 'http://localhost:17745/main' from origin 'http://localhost:1420' 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.

Seems like every single run changes the port rust is using. How do we change it to be 1420 since thats the default the create-tauri-app uses?

dominikbucher commented 11 months ago

I think it suffices to change "http://localhost:8080" to "http://localhost:1420" when initially setting up the invoke handler.

The reason is that in https://github.com/tauri-apps/tauri-invoke-http/blob/dev/src/lib.rs#L17 the "Origin" of the request of the WebView is 1420, and it only gets admitted (meaning written back to "Access-Control-Allow-Origin") if it's in the originally specified whitelist.