fix: middleware state reset between middlewares (#1500)

This commit is contained in:
Marvin Hagemeister
2023-07-24 11:03:11 +02:00
committed by GitHub
parent 0b96db4bae
commit 38d4b90091
10 changed files with 277 additions and 13 deletions
+13 -2
View File
@@ -477,6 +477,7 @@ export class ServerContext {
const handlers: (() => Response | Promise<Response>)[] = [];
const paramsAndRouteResult = paramsAndRoute(req.url);
let state: Record<string, unknown> = {};
const middlewareCtx: MiddlewareHandlerContext = {
next() {
const handler = handlers.shift()!;
@@ -496,7 +497,12 @@ export class ServerContext {
}
},
...connInfo,
state: {},
get state() {
return state;
},
set state(v) {
state = v;
},
destination: "route",
params: paramsAndRouteResult.params,
};
@@ -514,7 +520,12 @@ export class ServerContext {
const ctx = {
...connInfo,
state: middlewareCtx.state,
get state() {
return state;
},
set state(v) {
state = v;
},
};
const { destination, handler } = inner(
req,