Vue+fetch+nodejs,session failure problem

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 ());

Mar.17,2021

when the front and rear ends are developed separately, the cookie will not be passed when the ajax request is sent, so the session will change all the time

.

when I use axios to send a request, I set 'withCredentials' to true

this.$axios.get ( ${URL} , {withCredentials: true}). Then (res = > {})

Menu