Skip to content

Commit

Permalink
fix: add await to middleware response handling (#1588)
Browse files Browse the repository at this point in the history
* fix middleware wrapper

* revert wrapResponseMiddleware to use sendWebResponse

* Create heavy-panthers-confess.md

---------

Co-authored-by: Ryan Carniato <ryansolid@gmail.com>
Co-authored-by: Atila Fassina <atila@fassina.eu>
Co-authored-by: Katja Lutz <katywings@users.noreply.github.com>
  • Loading branch information
4 people authored Jan 31, 2025
1 parent d260b55 commit df32b0d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-panthers-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/start": patch
---

Await internal `sendWebResponse` calls for middlewares that return responses.
12 changes: 4 additions & 8 deletions packages/start/src/middleware/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ function wrapRequestMiddleware(onRequest: RequestMiddleware) {
return async (h3Event: HTTPEvent) => {
const fetchEvent = getFetchEvent(h3Event);
const response = await onRequest(fetchEvent);
if (!response) {
return;
} else {
sendWebResponse(h3Event, response);
if (response) {
await sendWebResponse(h3Event, response);
}
};
}
Expand All @@ -39,10 +37,8 @@ function wrapResponseMiddleware(onBeforeResponse: ResponseMiddleware) {
return async (h3Event: HTTPEvent, response: ResponseMiddlewareResponseParam) => {
const fetchEvent = getFetchEvent(h3Event);
const mwResponse = await onBeforeResponse(fetchEvent, response);
if (!mwResponse) {
return;
} else {
sendWebResponse(h3Event, mwResponse);
if (mwResponse) {
await sendWebResponse(h3Event, mwResponse);
}
};
}
Expand Down

0 comments on commit df32b0d

Please sign in to comment.