1- import { NextRequest , NextResponse } from "next/server" ;
1+ import { NextResponse } from "next/server" ;
2+ import { getEnvVariables } from "../utils" ;
23
34export async function GET ( ) {
45 try {
5- const result = await fetch ( `${ process . env . BACKEND_URL } /list_repos` , {
6+
7+ const { url, token } = getEnvVariables ( )
8+ const result = await fetch ( `${ url } /list_repos` , {
69 method : 'GET' ,
710 headers : {
8- "Authorization" : process . env . SECRET_TOKEN ! ,
11+ "Authorization" : token ,
912 } ,
1013 cache : 'no-store'
1114 } )
@@ -18,31 +21,40 @@ export async function GET() {
1821
1922 return NextResponse . json ( { result : repositories } , { status : 200 } )
2023 } catch ( err ) {
21- return NextResponse . json ( { message : ( err as Error ) . message } , { status : 400 } )
24+ console . error ( err )
25+ return NextResponse . json ( ( err as Error ) . message , { status : 400 } )
2226 }
2327}
2428
2529// export async function POST(request: NextRequest) {
30+
31+ // const repo_url = request.nextUrl.searchParams.get('url');
32+
33+ // try {
2634
27- // const url = request.nextUrl.searchParams.get('url');
35+ // if (!repo_url) {
36+ // throw new Error("URL parameter is missing");
37+ // }
38+
39+ // const { url, token } = getEnvVariables();
2840
29- // try {
30- // const result = await fetch(`${process.env.BEAKEND_URL}/process_repo`, {
41+ // const result = await fetch(`${url}/process_repo`, {
3142// method: 'POST',
32- // body: JSON.stringify({ repo_url: url , ignore: ["./.github", "./sbin", "./.git", "./deps", "./bin", "./build"] }),
43+ // body: JSON.stringify({ repo_url, ignore: ["./.github", "./sbin", "./.git", "./deps", "./bin", "./build"] }),
3344// headers: {
34- // "Authorization": process.env.SECRET_TOKEN! ,
45+ // "Authorization": token ,
3546// 'Content-Type': 'application/json'
36- // },
47+ // },
3748// cache: 'no-store'
38- // })
49+ // });
3950
4051// if (!result.ok) {
41- // throw new Error(await result.text())
52+ // throw new Error(await result.text());
4253// }
4354
44- // return NextResponse.json({ message: "success" }, { status: 200 })
55+ // return NextResponse.json({ message: "success" }, { status: 200 });
4556// } catch (err) {
46- // return NextResponse.json({ message: (err as Error).message }, { status: 400 })
57+ // console.error(err)
58+ // return NextResponse.json((err as Error).message, { status: 400 });
4759// }
4860// }
0 commit comments