1. Package the vue project and publish it in node, and there is no problem with getting session.
fetch
let requestConfig = {
credentials: "include",
method: type,
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
"Access-Control-Allow-Credentials": "true"
},
mode: "cors",
cache: "no-cache"
}
2. When the foreground and background are developed separately, the session cannot be obtained, and the sessionid has been changing
.let requestConfig = {
//credentials: "include",
method: type,
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
"Access-Control-Allow-Credentials": "true"
},
mode: "cors",
cache: "no-cache"
}
if credentials: "include", is not commented, an error will be reported:
Response to preflight request doesn"t pass access control check: 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:8001" is therefore not allowed access.
/ / to solve the cross-domain request in the background
app.use (cors ());