Fetching an API resource on mybb [CORS problem]
#1
Hello everyone ,
I'm trying to use an API on my mybb test forum and I get this error at every fetch on my console :
Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource.

It seems like there is some CORS problem , I tried to fix it by adding into my apache2 htaccess file this code , but it doesn't work :

<IfModule mod_headers.c>
  
    Header set Access-Control-Allow-Origin "*"
  
</IfModule>



Please help me guys !
Reply
#2
What’s the actual code you’re running? What is the API you’re calling?
MyReactions - All Plugins

Can you still feel the butterflies?

Free never tasted like pudding.
Reply
#3
So I'm running this code : fetch('http://v2.api.iphub.info/ip/${ipaddress}', {
"X-Key": 'APIKEY'

})
.then(response => response.json())
.then(data => console.log(data));

( the code I m using is bigger but I used this as an example .. maybe the problem is coming because I m not using async await ?? but I don t think so ..
Reply
#4
As far as I’m aware you won’t be able to do it. CORS needs to be set up on the remote server, not yours. You’ll need to do this API call server side.
MyReactions - All Plugins

Can you still feel the butterflies?

Free never tasted like pudding.
Reply
#5
(2022-03-06, 08:32 PM)Matt Wrote: As far as I’m aware you won’t be able to do it. CORS needs to be set up on the remote server, not yours. You’ll need to do this API call server side.
oh so I should do it in php ??
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)