File tree Expand file tree Collapse file tree 15 files changed +225
-9
lines changed
dev-packages/e2e-tests/test-applications/nextjs-14
test-outgoing-fetch-external-disallowed
test-outgoing-http-external-disallowed
packages/nextjs/src/server Expand file tree Collapse file tree 15 files changed +225
-9
lines changed Original file line number Diff line number Diff line change
1
+ import { checkHandler } from '../../utils' ;
2
+
3
+ export const dynamic = 'force-dynamic' ;
4
+
5
+ export const GET = checkHandler ;
Original file line number Diff line number Diff line change
1
+ import { NextResponse } from 'next/server' ;
2
+
3
+ export const dynamic = 'force-dynamic' ;
4
+
5
+ export async function GET ( ) {
6
+ const data = await fetch ( `http://localhost:3030/propagation/test-outgoing-fetch-external-disallowed/check` ) . then (
7
+ res => res . json ( ) ,
8
+ ) ;
9
+ return NextResponse . json ( data ) ;
10
+ }
Original file line number Diff line number Diff line change
1
+ import { checkHandler } from '../../utils' ;
2
+
3
+ export const dynamic = 'force-dynamic' ;
4
+
5
+ export const GET = checkHandler ;
Original file line number Diff line number Diff line change
1
+ import { NextResponse } from 'next/server' ;
2
+
3
+ export const dynamic = 'force-dynamic' ;
4
+
5
+ export async function GET ( ) {
6
+ const data = await fetch ( `http://localhost:3030/propagation/test-outgoing-fetch/check` ) . then ( res => res . json ( ) ) ;
7
+ return NextResponse . json ( data ) ;
8
+ }
Original file line number Diff line number Diff line change
1
+ import { checkHandler } from '../../utils' ;
2
+
3
+ export const dynamic = 'force-dynamic' ;
4
+
5
+ export const GET = checkHandler ;
Original file line number Diff line number Diff line change
1
+ import { NextResponse } from 'next/server' ;
2
+ import { makeHttpRequest } from '../utils' ;
3
+
4
+ export const dynamic = 'force-dynamic' ;
5
+
6
+ export async function GET ( ) {
7
+ const data = await makeHttpRequest ( `http://localhost:3030/propagation/test-outgoing-http-external-disallowed/check` ) ;
8
+ return NextResponse . json ( data ) ;
9
+ }
Original file line number Diff line number Diff line change
1
+ import { checkHandler } from '../../utils' ;
2
+
3
+ export const dynamic = 'force-dynamic' ;
4
+
5
+ export const GET = checkHandler ;
Original file line number Diff line number Diff line change
1
+ import { NextResponse } from 'next/server' ;
2
+ import { makeHttpRequest } from '../utils' ;
3
+
4
+ export const dynamic = 'force-dynamic' ;
5
+
6
+ export async function GET ( ) {
7
+ const data = await makeHttpRequest ( `http://localhost:3030/propagation/test-outgoing-http/check` ) ;
8
+ return NextResponse . json ( data ) ;
9
+ }
Original file line number Diff line number Diff line change
1
+ import http from 'http' ;
2
+ import { headers } from 'next/headers' ;
3
+ import { NextResponse } from 'next/server' ;
4
+
5
+ export function makeHttpRequest ( url : string ) {
6
+ return new Promise ( resolve => {
7
+ const data : any [ ] = [ ] ;
8
+ http
9
+ . request ( url , httpRes => {
10
+ httpRes . on ( 'data' , chunk => {
11
+ data . push ( chunk ) ;
12
+ } ) ;
13
+ httpRes . on ( 'error' , error => {
14
+ resolve ( { error : error . message , url } ) ;
15
+ } ) ;
16
+ httpRes . on ( 'end' , ( ) => {
17
+ try {
18
+ const json = JSON . parse ( Buffer . concat ( data ) . toString ( ) ) ;
19
+ resolve ( json ) ;
20
+ } catch {
21
+ resolve ( { data : Buffer . concat ( data ) . toString ( ) , url } ) ;
22
+ }
23
+ } ) ;
24
+ } )
25
+ . end ( ) ;
26
+ } ) ;
27
+ }
28
+
29
+ export function checkHandler ( ) {
30
+ const headerList = headers ( ) ;
31
+
32
+ const headerObj : Record < string , unknown > = { } ;
33
+ headerList . forEach ( ( value , key ) => {
34
+ headerObj [ key ] = value ;
35
+ } ) ;
36
+
37
+ return NextResponse . json ( { headers : headerObj } ) ;
38
+ }
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import http from 'http';
3
3
export const dynamic = 'force-dynamic' ;
4
4
5
5
export default async function Page ( ) {
6
- await fetch ( 'http://example.com/' , { cache : 'no-cache' } ) ;
6
+ await fetch ( 'http://example.com/' , { cache : 'no-cache' } ) . then ( res => res . text ( ) ) ;
7
7
await new Promise < void > ( resolve => {
8
8
http . get ( 'http://example.com/' , res => {
9
9
res . on ( 'data' , ( ) => {
You can’t perform that action at this time.
0 commit comments