Ich habe einige Probleme mit meinem node.js-Server. Ich habe es mit Heroku gestartet und möchte nun, dass meine Chrome-Erweiterung HTTP-Anfragen an den Server sendet (mit Hilfe von Cookies).Chrome-Erweiterung: HTTP-Anforderung an einen node.js-Server senden Cookie-Anmeldeinformationen (CORS) senden
Ich benutze express.js als meine Backend und ich habe Probleme beim Einrichten von CORS den richtigen Weg.
Dies ist, was ich in app.js haben:
if (process.env.NODE_ENV !== 'production') {
app.use(cors({
credentials: true,
origin: ['http://localhost:4200', 'http://localhost:8000', 'chrome-extension://kdfekbilmpafgiocanhihiogknfilcio']
}));
} else {
app.use(cors({
credentials: true,
origin: ['chrome-extension://kdfekbilmpafgiocanhihiogknfilcio']
}));
}
app.use(session({
secret: 'angular shhh secret auth',
resave: true,
saveUninitialized: true,
cookie : {
httpOnly: true,
expires: new Date(253402300000000)
}
}));
und ich mache Anfragen von meiner Chrom-Erweiterung (Client) wie folgt aus:
signUp(user) {
const options = { withCredentials: true };
return this.myHttp.post(`${this.BASE_URL}/signup`, user, options)
.toPromise()
.then((result) => {
result.json()
});
}
aaand das ist mein Fehler:
XMLHttpRequest cannot load
https://moodflowextension.herokuapp.com/loggedin. The value of the
'Access-Control-Allow-Origin' header in the response must not be the
wildcard '*' when the request's credentials mode is 'include'. Origin
'http://localhost:4200' is therefore not allowed access. The
credentials mode of requests initiated by the XMLHttpRequest is
controlled by the withCredentials attribute.
ich weiß, dass ich irgendwie in dem Cookie in der Kopfzeile passieren soll ...
ein Problem scheint zu sein, dass Ihr Server mit 'Access-Control-Allow-Origin: * 'antwortet - was ungültig ist, wenn withCredentials true ist (es sagt, genau dort, in dem Fehler) –