-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fixes existing production tests
- Loading branch information
Showing
8 changed files
with
44 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 2 additions & 24 deletions
26
test/production/middleware-typescript/app/pages/responses/_middleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,20 @@ | ||
import { NextMiddleware, NextResponse } from 'next/server' | ||
|
||
export const middleware: NextMiddleware = async function (request, ev) { | ||
// eslint-disable-next-line no-undef | ||
const { readable, writable } = new TransformStream() | ||
export const middleware: NextMiddleware = async function (request) { | ||
const url = request.nextUrl | ||
const writer = writable.getWriter() | ||
const encoder = new TextEncoder() | ||
const next = NextResponse.next() | ||
|
||
// Header based on query param | ||
if (url.searchParams.get('set-header') === 'true') { | ||
next.headers.set('x-set-header', 'valid') | ||
} | ||
|
||
// Streams a basic response | ||
if (url.pathname === '/responses/stream-a-response') { | ||
ev.waitUntil( | ||
(async () => { | ||
writer.write(encoder.encode('this is a streamed ')) | ||
writer.write(encoder.encode('response')) | ||
writer.close() | ||
})() | ||
) | ||
|
||
return new Response(readable) | ||
} | ||
|
||
if (url.pathname === '/responses/bad-status') { | ||
return new Response('Auth required', { | ||
return new Response(null, { | ||
headers: { 'WWW-Authenticate': 'Basic realm="Secure Area"' }, | ||
status: 401, | ||
}) | ||
} | ||
|
||
// Sends response | ||
if (url.pathname === '/responses/send-response') { | ||
return new NextResponse(JSON.stringify({ message: 'hi!' })) | ||
} | ||
|
||
return next | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/production/required-server-files/pages/middleware/_middleware.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export async function middleware(req) { | ||
return new Response('hello from middleware') | ||
return new Response(null, { headers: { data: 'hello from middleware' } }) | ||
} |