route.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { NextRequest, NextResponse } from 'next/server'
  2. export async function GET(request: NextRequest) {
  3. try {
  4. const searchParams = request.nextUrl.searchParams
  5. const page = searchParams.get('page') || '1'
  6. const pageSize = searchParams.get('pageSize') || '500'
  7. const address = searchParams.get('userAddress')
  8. const status = searchParams.get('status') || '0'
  9. const tokenAddress = searchParams.get('tokenAddress') || ''
  10. const response = await fetch(
  11. `https://api2.byreal.io/byreal/api/dex/v2/position/list?userAddress=${address}&page=${page}&pageSize=${pageSize}&tokenAddress=${tokenAddress}&status=${status}`,
  12. {
  13. method: 'GET',
  14. headers: {
  15. accept: 'application/json',
  16. },
  17. }
  18. )
  19. if (!response.ok) {
  20. return NextResponse.json(
  21. { retCode: response.status, retMsg: '外部 API 请求失败' },
  22. { status: response.status }
  23. )
  24. }
  25. const data = await response.json()
  26. return NextResponse.json(data)
  27. } catch (error) {
  28. console.error('API Route Error:', error)
  29. return NextResponse.json(
  30. { retCode: 500, retMsg: '服务器内部错误' },
  31. { status: 500 }
  32. )
  33. }
  34. }