File tree Expand file tree Collapse file tree 4 files changed +389
-2558
lines changed Expand file tree Collapse file tree 4 files changed +389
-2558
lines changed Original file line number Diff line number Diff line change 1- // /home/rust/workspace/cratespro-frontend/app/api/programs/route.ts
21import { NextRequest , NextResponse } from 'next/server' ;
3- import pool from '../../lib/db' ;
42
53export async function GET ( req : NextRequest ) {
64 try {
7- const client = await pool . connect ( ) ;
8- const res = await client . query ( 'SELECT name, description FROM programs' ) ;
9- client . release ( ) ;
5+ // 发送 HTTP 请求获取外部数据
6+ const externalApiUrl = 'http://210.28.134.203:6888/crates' ; // 替换为你的外部 API URL
7+ const externalRes = await fetch ( externalApiUrl ) ;
108
11- const programs = res . rows ;
9+ if ( ! externalRes . ok ) {
10+ throw new Error ( 'Failed to fetch external data' ) ;
11+ }
1212
13- return NextResponse . json ( programs ) ;
13+ const externalData = await externalRes . json ( ) ;
14+
15+ return NextResponse . json ( externalData ) ;
1416 } catch ( error ) {
15- console . error ( 'Database query error :' , error ) ;
17+ console . error ( 'Error :' , error ) ;
1618 return NextResponse . json ( { error : 'Internal Server Error' } , { status : 500 } ) ;
1719 }
1820}
You can’t perform that action at this time.
0 commit comments