axios in firefox
-
when i use axios in google chrome everything works fine but when i use firefox i get this message
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://localhost:44355/api/auth/Login. (Reason: CORS request did not succeed)
I don’t understand.
-
this is not quasar specific, it means you need to allow CORS in your backend api. googling will help you with this.
-
@metalsadman said in axios in firefox:
this is now quasar specific, it means you need to allow CORS in your backend api. googling will help you with this.
in my api, cors are enabled
why in chrome it works and in firefox it doesn’t work ?
-
@eloy-silva It will have something to do with your api server.
https://stackoverflow.com/questions/51831652/cors-request-did-not-succeed-on-firefox-but-works-on-chromeThe two browsers are not quite identical the way they handle this.
-
CORS is counterintuitive at first, but it is one of the most important technologies in terms of API security. You should understand not only what is needed from you to send some requests from client to server, but also, what benefits the CORS could give to you.
This is VERY nice interactive tutorial - worth checking:
https://httptoolkit.tech/will-it-cors/In the context of Quasar, which is amazing technology, on dev machines we should use a devServer configuration in quasar.conf.js:
https://quasar.dev/quasar-cli/quasar-conf-js#Options-to-Configure
This is essentially a webpack devserver so we could use the proxy to access the API from dev machine:
https://webpack.js.org/configuration/dev-server/#devserverproxy
In stage/qa and production environment it is also recommended to use reverse proxy with API endpoints, so yours dev configuration should be very similar to what you use in productions. In terms of quasar/axios, thanks to webpack devserver proxy, you can have just one code accesing your API as for example /api/v1/something/params/etc
Oh, and about differences in chrome/firefox - CORS uses some kind of timeout and browser could cache pre-flight requests so, if you really want to check a difference, you should open a new incognito windows in both browsers and check the operation in those windows once, and then close them, before next test.
-