spine, node.js (express) und Access-Control-Allow-Origin
Ich entwickle eine App auf meinem lokalen PC. Das Frontend sollte mit spinejs und das Backend-API mit node.js erstellt werden. Wirbelsäule läuft auf Port 9294 und node.js läuft auf Port 3000. In Wirbelsäule habe ich meinem Modell Folgendes hinzugefügt:
<code>@url: "http:localhost:3000/posts" </code>
und in meinem Express-Server
<code>app.get('/posts', function(req, res){ console.log("giving ALL the posts"); res.header("Access-Control-Allow-Origin", "*") res.json(posts); }); </code>
Aber ich bekomme immer den folgenden Fehler in Chrom:
<code>XMLHttpRequest cannot load http://localhost:3000/posts. Origin http://localhost:9294 is not allowed by Access-Control-Allow-Origin. </code>
Was muss ich tun, damit ich richtig auf meine API zugreifen kann? Ich füge zwar den Header in die Antworten ein, behebt aber das Problem.