File tree Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { NextRequest , NextResponse } from "next/server" ;
2
+
3
+ const TARGET_SERVER_BASE_URL = process . env . SERVER_BASE_URL || 'http://localhost:8001' ;
4
+
5
+ export async function GET ( request : NextRequest ) {
6
+ try {
7
+ // Forward the request to the backend API
8
+ const response = await fetch ( `${ TARGET_SERVER_BASE_URL } /auth/status` , {
9
+ method : 'GET' ,
10
+ headers : {
11
+ 'Content-Type' : 'application/json' ,
12
+ } ,
13
+ } ) ;
14
+
15
+ if ( ! response . ok ) {
16
+ return NextResponse . json (
17
+ { error : `Backend server returned ${ response . status } ` } ,
18
+ { status : response . status }
19
+ ) ;
20
+ }
21
+
22
+ const data = await response . json ( ) ;
23
+ return NextResponse . json ( data ) ;
24
+ } catch ( error ) {
25
+ console . error ( 'Error forwarding request to backend:' , error ) ;
26
+ return NextResponse . json (
27
+ { error : 'Internal Server Error' } ,
28
+ { status : 500 }
29
+ ) ;
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ import { NextRequest , NextResponse } from "next/server" ;
2
+
3
+ const TARGET_SERVER_BASE_URL = process . env . SERVER_BASE_URL || 'http://localhost:8001' ;
4
+
5
+ export async function POST ( request : NextRequest ) {
6
+ try {
7
+ const body = await request . json ( ) ;
8
+
9
+ // Forward the request to the backend API
10
+ const response = await fetch ( `${ TARGET_SERVER_BASE_URL } /auth/validate` , {
11
+ method : 'POST' ,
12
+ headers : {
13
+ 'Content-Type' : 'application/json' ,
14
+ } ,
15
+ body : JSON . stringify ( body ) ,
16
+ } ) ;
17
+
18
+ if ( ! response . ok ) {
19
+ return NextResponse . json (
20
+ { error : `Backend server returned ${ response . status } ` } ,
21
+ { status : response . status }
22
+ ) ;
23
+ }
24
+
25
+ const data = await response . json ( ) ;
26
+ return NextResponse . json ( data ) ;
27
+ } catch ( error ) {
28
+ console . error ( 'Error forwarding request to backend:' , error ) ;
29
+ return NextResponse . json (
30
+ { error : 'Internal Server Error' } ,
31
+ { status : 500 }
32
+ ) ;
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments