problem description
I"m going to get the token parameters stored in cookie in middleware
No problem was found in the local test,
but after uploading to the official server for a period of time, I found that some users had the same token
after checking, it is found that because multiple users have requested the server at the same time, the triggered middleware may have been rewritten (it is not clear how to describe it)
the environmental background of the problems and what methods you have tried
when multiple users request a page at the same time, the value of the context.req.headers.cookie field in
middleware is the same
at first, I thought that the temporary variable saved by myself was repeatedly queried by the server, but the problem was still found after deletion
.related codes
let getCookie = (cname, cookie) => {
let name = cname + "=";
let ca = cookie.split(";");
let cname_index = cookie.indexOf(name)
if (cname_index >= 0) {
for (let i = 0; i < ca.length; iPP) {
let c = ca[i].trim();
if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
}
} else {
return null;
}
}
export default (context) => {
if (context.route.name) {
context.marsToken = getCookie("MarsToken", process.server ? (context.req.headers.cookie || "") : (document.cookie || ""));
context.store.commit("SAVETOKEN", context.marsToken);
}
}
what result do you expect? What is the error message actually seen?
I would like to ask why this happens because node cannot handle concurrent requests. If so, how can I improve it?
or is it a framework problem?