TGViewer
𝙎𝙖𝙫𝙚𝙙 𝙢𝙚𝙨𝙨𝙖𝙜𝙚𝙨 𝙎𝙖𝙫𝙚𝙙 𝙢𝙚𝙨𝙨𝙖𝙜𝙚𝙨 @parsa_tool · 11.1K subscribers
Post #151 14.6K
کد index.js مربوط به آموزش Vercel:

export const config = { runtime: "edge" };

const TARGET_BASE = (process.env.TARGET_DOMAIN || "").replace(/\/$/, "");

const STRIP_HEADERS = new Set([
"host",
"connection",
"keep-alive",
"proxy-authenticate",
"proxy-authorization",
"te",
"trailer",
"transfer-encoding",
"upgrade",
"forwarded",
"x-forwarded-host",
"x-forwarded-proto",
"x-forwarded-port",
]);

export default async function handler(req) {
if (!TARGET_BASE) {
return new Response("Misconfigured: TARGET_DOMAIN is not set", { status: 500 });
}

try {
const pathStart = req.url.indexOf("/", 8);
const targetUrl =
pathStart === -1 ? TARGET_BASE + "/" : TARGET_BASE + req.url.slice(pathStart);

const out = new Headers();
let clientIp = null;
for (const [k, v] of req.headers) {
if (STRIP_HEADERS.has(k)) continue;
if (k.startsWith("x-vercel-")) continue;
if (k === "x-real-ip") {
clientIp = v;
continue;
}
if (k === "x-forwarded-for") {
if (!clientIp) clientIp = v;
continue;
}
out.set(k, v);
}
if (clientIp) out.set("x-forwarded-for", clientIp);

const method = req.method;
const hasBody = method !== "GET" && method !== "HEAD";

return await fetch(targetUrl, {
method,
headers: out,
body: hasBody ? req.body : undefined,
duplex: "half",
redirect: "manual",
});
} catch (err) {
console.error("relay error:", err);
return new Response("Bad Gateway: Tunnel Failed", { status: 502 });
}
}
  • ❤ 31
  • 👍 4
More from @parsa_tool
  1. Apr 29, 2026فایل استفاده شده در آموزش اتصال با کمک Netlify.
  2. Apr 27, 2026فایل استفاده شده در آموزش اتصال با کمک Vercel.
  3. Apr 25, 2026فایل برنامه Http Relay برای اندروید.
  4. Apr 21, 2026فایل دستورات استفاده شده برای آموزش Http Relay.
  5. Apr 21, 2026فایل مورد نیاز برای آموزش Http Relay.
  6. Apr 19, 2026اپدیت نسخه لایت اسلیپ نت
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →