Fetch request how to join session?

the project uses a request made by fetch, and the background says that session can be used to handle session permissions! But how to add session in the request header.

after looking up the information, it is said that request.getSession can get it, but there is some doubt that request, can not be found in the request encapsulated by fetch. How to encapsulate it.

export const get = (url, query = {}, options = {}) => {
  const defaultOpt = {
    method: "GET",
    timeout: requestTimeOut,
    credentials: "include",
    headers: { ...options }
  }

  defaultOpt.headers = completeHeader(defaultOpt.headers)
  console.log(defaultOpt)
  return fetch(getUrl(url, query), defaultOpt).then(checkStatus).then(parseJSON)
}

above is one of the examples

the Internet also says to join credentials: "include", but I still don"t quite understand.

Mar.30,2021

generally the sessionid is placed in the cookie, and the session is saved in the background. When sending a request to the server, the cookie, in the same domain does not need to be manually set


that is, credentials is added. The fetch request header cannot get sessionid, plus by default without cookie, backend.


fetch does not have cookie by default. If it is in the same domain, add mode

.
const defaultOpt = {
    mode: "same-origin",
    credentials: "same-origin",
    ...
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b8d5-2baf6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b8d5-2baf6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?