Hello, I have a few dumb questions here
mnba3223 opened this issue · 6 comments
My first question is about using get request, that I be blocked by CORS.
I tried to use vite-plugin-cross-origin-isolation and tried to use the official proxy configure setting, but it still didn’t work. I don't know why.
second question is serve:native can't used. console said that VITE_HTTP_HANDLER is not recognized as an internal or external command, operable program or batch file. did I miss something or forgot to install some tool?
@mnba3223 These problems have probably happened because you are using windows.
In general, CORS may happen when you are making HTTP requests inside a browser environment (Tauri). Read about it here.
To mitigate this, we must either change configuration at server side or make the HTTP request outside of the browser environment. Since Tauri provides a Http module, i used that in this project. I use VITE_HTTP_HANDLER
env var to quickly switch between Tauri Http module and native browser (with axios through YNetwork).
You can do 2 things to fix this problem in windows.
- do
set VITE_HTTP_HANDLER=NATIVE
before you doserver:native
(and remove VITE_HTTP_HANDLER=NATIVE from the package.json script) - change this file
./src/plugins/configure-ynetwork.js
as below
// change this
if (import.meta.env.VITE_HTTP_HANDLER === 'NATIVE') {
YNetwork.requestRunner = tauriReuestResolver;
}
// to this
YNetwork.requestRunner = tauriReuestResolver;
@yooneskh Thank you for your answer.
But I follow your steps like this, still same problem, did I do something wrong? or I need to use tauri environment?
and I used yarn serve:tauri the browser has appeared but can't connect local host. (ERR_CONNECTION_REFUSED).
or I need change to ubuntu to use this template?
Sorry I'm so stupid can't figure it out.
@mnba3223 Feel free to ask your questions.
You are using yarn serve
and i suppose you are using a normal browser to test. This way, you have no option to get around CORS (Tauris Http module works only IN tauri). The only way to get around CORS in browser is to use extensions which i don't recommend.
In your case, since you have changed the configure-ynetwork file, you dont need the set ....
command. Run yarn serve
in one terminal and yarn serve:tauri
in another. It should work in the Tauris window.
It is weird. I will check to see if there is any problem.
@mnba3223 There was a problem with passing tauriRequestResolver
to YNetwork
in serve:native
and is now fixed and works. Thanks for your patience. Open two terminals and in one, run serve:native
and in another run serve:tauri
, it should work now.
I will close this issue. Reopen if the issue persists.