route.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { NextRequest, NextResponse } from 'next/server'
  2. interface RequestBody {
  3. poolAddress?: string
  4. parentPositionAddress?: string
  5. page?: number
  6. pageSize?: number
  7. sortField?: string
  8. status?: number
  9. }
  10. export async function POST(request: NextRequest) {
  11. try {
  12. const body: RequestBody = await request.json()
  13. // console.log(body.pageSize)
  14. const response = await fetch(
  15. 'https://api2.byreal.io/byreal/api/dex/v2/copyfarmer/top-positions',
  16. {
  17. method: 'POST',
  18. headers: {
  19. accept: 'application/json',
  20. 'content-type': 'application/json',
  21. },
  22. body: JSON.stringify({
  23. poolAddress:
  24. body.poolAddress || 'FPBW9dtVRoUug2BeUKZAzaknd6iiet9jHM8RcTvwUkyC',
  25. ...(body.parentPositionAddress && {
  26. parentPositionAddress: body.parentPositionAddress,
  27. }),
  28. page: body.page || 1,
  29. pageSize: body.pageSize || 5,
  30. sortField: body.sortField || 'liquidity',
  31. status: body.status ?? 0,
  32. }),
  33. }
  34. )
  35. if (!response.ok) {
  36. return NextResponse.json(
  37. { code: response.status, message: '外部 API 请求失败' },
  38. { status: response.status }
  39. )
  40. }
  41. const data = await response.json()
  42. return NextResponse.json(data)
  43. } catch (error) {
  44. console.error('API Route Error:', error)
  45. return NextResponse.json(
  46. { code: 500, message: '服务器内部错误' },
  47. { status: 500 }
  48. )
  49. }
  50. }