ist habe ich ein SetupCORS: Kann nicht Wildcard in Access-Control-Allow-Origin verwenden, wenn Anmeldeinformationen Flag true
Frontend-Server beteiligt (Node.js, Domäne: localhost: 3000) < ---> Backend (Django, ajax, Domain: localhost: 8000)
Browser < - Webapp < - Node.js (Serve the app)
Browser (Webapp) -> ajax -> Django (Serve ajax POST Anfragen)
Jetzt ist mein Problem hier mit CORS-Setup, mit dem die Webanwendung Ajax-Aufrufe an den Backend-Server durchführt. In Chrom bekomme ich immer
Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true.
funktioniert nicht auf Firefox auch nicht.
Mein Node.js Setup ist:
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', 'http://localhost:8000/');
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
};
Und in Django Ich verwende this middlewarealong with this
Die Webapp macht Anfragen als solche:
$.ajax({
type: "POST",
url: 'http://localhost:8000/blah',
data: {},
xhrFields: {
withCredentials: true
},
crossDomain: true,
dataType: 'json',
success: successHandler
});
Also, die Request-Header dass die webapp sendet sieht aus wie:
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: "Origin, X-Requested-With, Content-Type, Accept"
Access-Control-Allow-Methods: 'GET,PUT,POST,DELETE'
Content-Type: application/json
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Cookie: csrftoken=***; sessionid="***"
Und hier ist die Antwort-Header:
Access-Control-Allow-Headers: Content-Type,*
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE
Content-Type: application/json
Wo ich falsch werde ?!
Edit 1: Ich habe chrome --disable-web-security
verwendet, aber jetzt wollen Dinge tatsächlich funktionieren.
Edit 2: Antwort:
So Lösung für mich django-cors-headers
config:
CORS_ORIGIN_ALLOW_ALL = False
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_WHITELIST = (
'http://localhost:3000' # Here was the problem indeed and it has to be http://localhost:3000, not http://localhost:3000/
)
... Ich liebe dich .. .Ich verbrachte Stunden damit, es zu debuggen .... verdammt Firefox gab keine Nachricht zurück! – Daviddd
Für mich ist es localhost: 3000 ohne http, wie folgt aus: CORS_ORIGIN_WHITELIST = ( 'localhost: 3000', ) – Andrei
Haben Sie meinen Sie das Frontend und Backend in einem PC verwenden entwickeln? – fanhualuojin154873