| 1 | // api/pypi.ts — proxy to pypistats.org for download counters |
| 2 | |
| 3 | function pypiApiPath(reqUrl: string | undefined): string { |
| 4 | if (!reqUrl) return "/packages/codegraphcontext/recent"; |
| 5 | |
| 6 | try { |
| 7 | const pathname = reqUrl.startsWith("http") |
| 8 | ? new URL(reqUrl).pathname |
| 9 | : reqUrl.split("?")[0]; |
| 10 | const stripped = pathname.replace(/^\/api\/pypi/, "") || "/packages/codegraphcontext/recent"; |
| 11 | return stripped.startsWith("/") ? stripped : `/${stripped}`; |
| 12 | } catch { |
| 13 | return "/packages/codegraphcontext/recent"; |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | export default async function handler(req: any, res: any) { |
| 18 | res.setHeader("Access-Control-Allow-Origin", "*"); |