Can someone please give me a more beginner oriented explanation for CORS? I read up on it and watched some stuff but I just don't get it :*
r
rocketraman
08/09/2018, 5:28 AM
The basic idea is that CORS is a way for servers to tell browsers, via headers, what they are and are not allowed do with respect to cross-origin requests i.e. requests to origins other than the one that loaded the page. Does that help?
f
frellan
08/09/2018, 7:04 AM
I have problems with this too, how do this work when you have a SPA? The SPA can call whatever but the server cant? I dont get it.
t
tipsy
08/09/2018, 1:44 PM
there is no difference between an SPA an a old fashioned "website"
tipsy
08/09/2018, 1:50 PM
if spa/website is running on a different origin, it will have to ask for permission before sending certain requests (POST/PUT/ETC). the client does this by sending pre-flight requests (OPTIONS) to the server.
when the server receives these OPTIONS requests, it determines what should be allowed and attaches headers to the responses
if the appropriate header is set, the client (spa/website) will then be able to perform the request it wanted to (POST/PUT/ETC)
h
Hamza
08/09/2018, 1:53 PM
So it's pretty much to protect your data from people stealing data from headers