| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import { NextRequest, NextResponse } from 'next/server'
- interface RequestBody {
- poolAddress?: string
- parentPositionAddress?: string
- page?: number
- pageSize?: number
- sortField?: string
- status?: number
- }
- export async function POST(request: NextRequest) {
- try {
- const body: RequestBody = await request.json()
- // console.log(body.pageSize)
- const response = await fetch(
- 'https://api2.byreal.io/byreal/api/dex/v2/copyfarmer/top-positions',
- {
- method: 'POST',
- headers: {
- accept: 'application/json',
- 'content-type': 'application/json',
- },
- body: JSON.stringify({
- poolAddress:
- body.poolAddress || 'FPBW9dtVRoUug2BeUKZAzaknd6iiet9jHM8RcTvwUkyC',
- ...(body.parentPositionAddress && {
- parentPositionAddress: body.parentPositionAddress,
- }),
- page: body.page || 1,
- pageSize: body.pageSize || 5,
- sortField: body.sortField || 'liquidity',
- status: body.status ?? 0,
- }),
- }
- )
- if (!response.ok) {
- return NextResponse.json(
- { code: response.status, message: '外部 API 请求失败' },
- { status: response.status }
- )
- }
- const data = await response.json()
- return NextResponse.json(data)
- } catch (error) {
- console.error('API Route Error:', error)
- return NextResponse.json(
- { code: 500, message: '服务器内部错误' },
- { status: 500 }
- )
- }
- }
|