Polling the Lusternia API from Nexus despite CORS

Amongst the reasons I've heard that "Nexus suxxors!" is that people can't poll the Lusternia API in it, due to CORS, to do things like pull someone's faction. So here's a trivially simple way to do the impossible.
fetch('https://cors-anywhere.herokuapp.com/https://api.lusternia.com/characters/lendren.json')
    .then((response) => {
    return response.json();
})
.then(data => {
    display_notice(data.fullname + ' is of ' + data.faction, 'lightgreen');
})
.catch(error => {
    display_notice('error '+ error, 'red');
}); 
By using the reliable cors-anywhere proxy you can easily pull the JSON through CORS by simply adding a prefix to the fetch URL, then parse and use it as normal. No significant performance impact involved. I've been using this proxy for about two years without any outages or problems on an unrelated project, but if it ever fails, it'd be simple to switch one of the dozen or so others that are out there.

Hope this is helpful for folks.

Comments

  • Thread necromancy! As a result of the discussions from the Nexus 3 testing, they've added the CORS headers to the Lusternia server and now this kind of trickery is no longer needed!

    (And good thing too. CORS-Anywhere closed down years ago.)
Sign In or Register to comment.