1+ import { getEnvVariables } from "@/app/api/utils" ;
12import { NextRequest , NextResponse } from "next/server" ;
23
3- export async function GET ( request : NextRequest , { params } : { params : { graph : string , node : string } } ) {
4+ export async function POST ( request : NextRequest , { params } : { params : Promise < { graph : string , node : string } > } ) {
45
5- const nodeId = parseInt ( params . node ) ;
6- const graphId = params . graph ;
7- try {
8-
9- const result = await fetch ( `${ process . env . BACKEND_URL } /get_neighbors?repo=${ graphId } &node_id=${ nodeId } ` , {
10- method : 'GET' ,
11- headers : {
12- "Authorization" : process . env . SECRET_TOKEN ! ,
13- }
14- } )
15-
16- const json = await result . json ( )
6+ const p = await params ;
177
18- return NextResponse . json ( { result : json } , { status : 200 } )
19- } catch ( err ) {
20- return NextResponse . json ( { massage : ( err as Error ) . message } , { status : 400 } )
21- }
22- }
8+ const repo = p . graph ;
9+ const src = Number ( p . node ) ;
10+ const dest = Number ( request . nextUrl . searchParams . get ( 'targetId' ) )
2311
24- export async function POST ( request : NextRequest , { params } : { params : { graph : string , node : string } } ) {
12+ try {
2513
26- const nodeId = params . node ;
27- const graphId = params . graph ;
28- const targetId = request . nextUrl . searchParams . get ( 'targetId' )
14+ if ( ! dest ) {
15+ throw new Error ( "targetId is required" ) ;
16+ }
2917
30- try {
18+ const { url , token } = getEnvVariables ( )
3119
32- const result = await fetch ( `${ process . env . BACKEND_URL } /find_paths` , {
20+ const result = await fetch ( `${ url } /find_paths` , {
3321 method : 'POST' ,
3422 headers : {
35- "Authorization" : process . env . SECRET_TOKEN ! ,
23+ "Authorization" : token ,
3624 'Content-Type' : 'application/json'
3725 } ,
3826 body : JSON . stringify ( {
39- repo : graphId ,
40- src : Number ( nodeId ) ,
41- dest : Number ( targetId ! )
42- } )
27+ repo,
28+ src,
29+ dest
30+ } ) ,
31+ cache : 'no-store'
4332 } )
4433
4534 if ( ! result . ok ) {
@@ -50,6 +39,7 @@ export async function POST(request: NextRequest, { params }: { params: { graph:
5039
5140 return NextResponse . json ( { result : json } , { status : 200 } )
5241 } catch ( err ) {
53- return NextResponse . json ( { massage : ( err as Error ) . message } , { status : 200 } )
42+ console . error ( err )
43+ return NextResponse . json ( ( err as Error ) . message , { status : 400 } )
5444 }
5545}
0 commit comments