#CORS issue

56 messages · Page 1 of 1 (latest)

finite narwhal
#

hi, I'm having a very weird issue related to CORS which I've had before and fixed, but I can't seem to fix it again. I'm trying to do a GET request to an API, but i'm getting this error:

Access to fetch at 'https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=APIKEY' from origin 'https://MYWEBSITE.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

I've been trying to fix it for the entire day but nothing works and I cannot find any new information online. this is how i'm doing my request:

fetch("https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=APIKEY&steamids=MYID").then(function(response) {
                // Convert to JSON
                return response.json();
            }).then(function(j) {
                // Yay, `j` is a JavaScript object
                console.log(JSON.stringify(j));
            }).catch(function(error) {
                console.log('Request failed', error)
            });

help would very much be appreciated

mellow gale
#

Pin in #help-chat

#

Basically, you can't fix it client-side

#

Make the request from your own server

#

Also, never use .then

finite narwhal
#

how? i fixed on a different web page client-side

#

i see people online saying I should make a server, but I found no logical explanation as to how that would fix anything. the request would then be sent from a server which would get the same error

mellow gale
#

I found no logical explanation as to how that would fix anything?
I have no idea where you looked at but damn, it's pretty fucking clear in the pin. The logic is "browsers don't allow you to do whatever you want with client side code"

finite narwhal
#

i do understand that, however i cannot find a reason as to how that correlates to my issue

#

especially since I've managed to correct that previously with a header, which now is not working for the same issue

mellow gale
#

Because you cannot solve a CORS issue client-side

#

Then the server was meant to work with CORS access. The steam api may not have been

finite narwhal
#

seems like i can by defining the access-control-allow-origin header?

mellow gale
#

No

#

It's not possible from client-side code

finite narwhal
#

okay, then another one - why then if I download a cors plugin for my browser, that works?

#

yet still, what would doing the request from a server solve? wouldnt it get the same error?

mellow gale
#

Because the plugin removed your browser protection

finite narwhal
#

that's what i cannot find the explanation for

finite narwhal
mellow gale
#

Not in a regular browser

#

In a destroyed browser

finite narwhal
#

..

mellow gale
#

CORS is implemented in browsers for security reasons. You may wish to bypass this security

#

Same as you can remove the fuse from your electric devices

#

It's client side, it's a fuse in your house, you have access to it. Should you remove it? Probably not

finite narwhal
#

okay

#

what would doing the request from a server solve? wouldnt it get the same error?

finite narwhal
mellow gale
#

These posts are blatantly wrong

#

If it's from SO (stackoverflow), don't pay attention to it

mellow gale
finite narwhal
#

then that means I would be able to do the request through PHP instead of JS

mellow gale
#

You would need to, yes

#

Note that JS can also be used to create servers

finite narwhal
#

i'd much rather not

mellow gale
#

But if you have experience with other languages, go ahead

finite narwhal
#

i will attempt that and come back, thanks for the tips

#

works in php

#

jesus christ I hate javascript more than I already did

mellow gale
#

JS is amazing, but browsers are akin to a mini-OS now with sensitive data and capabilities stored in them. The better they isolate processes, the better it is for the lambda user

#

Servers don't work with the same capabilities, they are concerned with other security models

#

JS has nothing to do with that, and a lot of people successfully work with JS to create some good stuff

finite narwhal
#

i know how this works

#

i am terribly frustrated that no one has thought of suggesting the use of PHP for such a simple issue in any of the dozens of posts I've looked for, and instead suggest simply defining the header, which doesn't work

mellow gale
#

Well PHP isn't used as often anymore

#

The posts you looked at are also probably from the same people not knowing a single thing

finite narwhal
#

if you look for the issue you'll find dozens of posts suggesting the same fixes, im sure many of those people do know what theyre talking about, but i digress

finite narwhal
#

is it due to the rise of other languages & systems you reckon?

#

ive been working with php for years and everything ive done, simple or complex, has always just worked

mellow gale
finite narwhal
#

oh how i love the and the self-proclaimed master developers

mellow gale
#

So people used to work with client-side JS can transfer their skill to almost anything coding related

#

And modern (2018+) JS is simple, if you learn with the correct resources