export async function GET(request) {
  const { searchParams } = new URL(request.url)
  const endpoint = searchParams.get('endpoint')
  const page = searchParams.get('page') || '1'
  const limit = searchParams.get('limit') || '12'
  const search = searchParams.get('search') || ''

  if (!endpoint) {
    return Response.json({ error: 'Endpoint required' }, { status: 400 })
  }

  try {
    const url = `https://api.aetheris.lol/api/${endpoint}?page=${page}&limit=${limit}&search=${search}`
    
    const response = await fetch(url, {
      headers: {
        'Cookie': 'ATHRSECURITY=sess_7f42a6abb6d94d1e8a9fc52cbe7e9df4; cf_clearance=UMDVIKzXJSpNeK19fs2pCu05JP7UrciOp9uvVMuzbZ0-1776698135-1.2.1.1-TTU.UgkCk80IweVnt1vBO8UjsZz38BK9KdbuvQbOf4KXt9TzM.S.MStt4LDLzSUEedw0Wen9O92v6yvTTE6CHI9NvlB8Ziuqcl6Ko_rccd3jWWbcb0TolwMw4N36vXdcKPoAY.h56PcyZqtAjK1DfdA571.YtcVjxp9HhioWw2t9i9CZXaY74tj4Uesote9MvZvGfu1cHUEw3lacwdsZ5tFwdNSWmgE8Tmp1Aqfea_5475jGdJe62fWy9ReNuD1grSdbH.97QiN_M0x5Rt0GN7n_LG5UQBc10Nl8gE3qOPM76eZsLOjPbVwL78J7tOcPpjD5DNzX3gwv8PbdHwriog',
        'User-Agent': 'Mozilla/5.0',
        'Accept': 'application/json',
      },
    })

    const data = await response.json()
    return Response.json(data)
  } catch (error) {
    return Response.json({ error: error.message }, { status: 500 })
  }
}
