Skip to content

Commit

Permalink
Fix middleware response handling (#134)
Browse files Browse the repository at this point in the history
This fixes the handling of custom responses
from the middleware handlers. Comparing the
instance to a `NextResponse` object was not
working while using the `Response` object that
the NextResponse object is also inherited from,
seems to fix the issue so that custom responses
from middlewares work.
  • Loading branch information
blomqma committed Feb 25, 2024
1 parent cef1bb1 commit ef863bc
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/next-rest-framework/src/app-router/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const route = <T extends Record<string, RouteOperationDefinition>>(
const isOptionsResponse = (res: unknown): res is BaseOptions =>
typeof res === 'object';

if (res instanceof NextResponse) {
if (res instanceof Response) {
return res;
} else if (isOptionsResponse(res)) {
middlewareOptions = res;
Expand All @@ -67,7 +67,7 @@ export const route = <T extends Record<string, RouteOperationDefinition>>(
middlewareOptions
);

if (res2 instanceof NextResponse) {
if (res2 instanceof Response) {
return res2;
} else if (isOptionsResponse(res2)) {
middlewareOptions = res2;
Expand All @@ -80,7 +80,7 @@ export const route = <T extends Record<string, RouteOperationDefinition>>(
middlewareOptions
);

if (res3 instanceof NextResponse) {
if (res3 instanceof Response) {
return res3;
} else if (isOptionsResponse(res3)) {
middlewareOptions = res3;
Expand Down

0 comments on commit ef863bc

Please sign in to comment.