Spaces:
Running
Running
Download frontend/app/api/proxy/telegram/route.ts from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 1.64 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/frontend/app/api/proxy/telegram/route.ts
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/frontend/app/api/proxy/telegram/route.ts
-
curl -L -o route.ts https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/frontend/app/api/proxy/telegram/route.ts
1.64 kB
| import { NextRequest, NextResponse } from "next/server"; | |
| export const runtime = 'edge'; // Use Edge Runtime for speed | |
| export async function POST(req: NextRequest) { | |
| try { | |
| const searchParams = req.nextUrl.searchParams; | |
| const token = searchParams.get("token"); | |
| const method = searchParams.get("method"); | |
| if (!token || !method) { | |
| return NextResponse.json( | |
| { error: "Missing 'token' or 'method' query parameters" }, | |
| { status: 400 } | |
| ); | |
| } | |
| const telegramUrl = `https://api.telegram.org/bot${token}/${method}`; | |
| // Forward the request to Telegram | |
| const response = await fetch(telegramUrl, { | |
| method: "POST", | |
| headers: req.headers, // Pass original headers (Content-Type etc.) | |
| body: req.body, // Stream the original body (JSON or FormData) | |
| // @ts-ignore - duplplex needed for streaming uploads in some environments, harmless if ignored | |
| duplex: 'half' | |
| }); | |
| // Stream the response back to the client | |
| return new NextResponse(response.body, { | |
| status: response.status, | |
| statusText: response.statusText, | |
| headers: response.headers, | |
| }); | |
| } catch (error: any) { | |
| console.error("Telegram Proxy Error:", error); | |
| return NextResponse.json( | |
| { error: "Proxy failed", details: error.message }, | |
| { status: 500 } | |
| ); | |
| } | |
| } | |
| // Allow GET for simple health checks or simple methods like getMe | |
| export async function GET(req: NextRequest) { | |
| return POST(req); | |
| } | |