I'm developing an app with Aurelia.io using Discogs API. Well, it's Javascript, for the ones who may not know Aurelia (I don't know if it's famous yet).
I'm writing this (of course xxx are the real values):
import {HttpClient} from 'aurelia-http-client';
let client = new HttpClient()
.configure(x => {
x.withHeader('User-Agent', 'myApp/0.1'),
x.withHeader('Authorization', 'Discogs key=xxxxx, secret=xxxxx'),
x.withHeader('Access-Control-Allow-Origin', '*')
});
client.get('https://api.discogs.com/releases/'+value.discogsReference)
.then(data => {
console.log(data.tracklist[value.releasePosition]);
});
Actually, my request doesn't work. Here are the headers Firefox is sending, whereas I want to send other ones as you can see in my code:
Host: api.discogs.com
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Access-Control-Request-Method: GET
Access-Control-Request-Headers: access-control-allow-origin,authorization,user-agent
Origin: http://localhost:9000
Connection: keep-alive
Apparently, the headers I want to force are not taken into account.
Here is the French message I'm getting in the console (I don't find on the web the translation):
Blocage d’une requête multiorigines (Cross-Origin Request) : la politique « Same Origin » ne permet pas de consulter la ressource distante située sur https://api.discogs.com/releases/2275022. Raison : jeton « access-control-allow-origin » manquant dans l’en-tête CORS « Access-Control-Allow-Headers » du canal de pré-vérification des requêtes CORS.
What am I doing wrong? Thanks
Cesar
OK I handled the problem the wrong way. Actually it is NOT possible to contact Discogs API like I did. You have to use a webservice accessing Discogs API. So, I created a custom local node webservice, using libcurl (https://www.npmjs.com/package/node-libcurl). My aurelia calls this webservice, libcurl allowing me to call Discogs API with proper headers. Phew, I made it, but I encountered other problems I'm going to post about on stackoverflow...