Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to avoid cors error with vue.js-cors?


Asked by Kian Boyer on Dec 01, 2021 Vue.js 2.0



Also make sure your server has enabled CORS The 'Access-Control-Allow-Origin' is type of response header and this must be set by the server. So you need to change the server's CORS policy to allow your origin: http://localhost:63342 . You can use Proxy server to avoid CORS Error.
Furthermore,
But sometimes it is required to send a request to another service-- server, back-end, API, and etc. CORS makes it possible to set a specific header on the request to the server. you can read widely about Cross-Origin Resource Sharing (CORS). In my case, I was serving my Vuejs project on localhost and the API service was running on the server.
Besides, If the CORS configuration isn't setup correctly, the browser console will present an error like "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at $somesite" indicating that the request was blocked due to violating the CORS security rules.
Thereof,
Browsers protect web applications to interact only with apps that are from the same origin. This is a policy called same-origin. But sometimes it is required to send requests to another server. CORS or Cross-Origin Resource Sharing is a standard that makes cross-origin requests possible by setting specific headers for requests.
Also,
It works by sending some HTTP headers with HTTP responses, that tell web browsers to enable or block frontend JavaScript code, from accessing responses. CORS headers are simply HTTP headers that tell a browser to allow a web application running at some origin (domain) to access specific resources from a server at a different origin.