[RESOLVED] 'Access-Control-Allow-Origin' header is present on the requested resource


#1

Hey Community!

I was attempting to get data from this page:

https://discord-channel-bot.glitch.me/stats

It worked, but I got the following error:
'Access-Control-Allow-Origin' header is present on the requested resource.

I know this is a CORS error, but I don’t know how to allow it to get the JSON file on a different glitch project.

Thanks,
Codingpro


#2

So you’re trying to get https://discord-channel-bot.glitch.me/stats from another Glitch project and getting that error?

This might help if discord-channel-bot uses express


#3

I see. I’m currently using Jquery right now tho. Would this code go on the data side or the GET side? The data side has express.


#4

Never Mind! It worked! I put it on the data side, and I don’t seem to get the error anymore!


#5

FIXED


Solution:
Paste the following code before any other express code:

  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});

#6

Oh great, yeah was just checking it and looked right!