-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.js
More file actions
49 lines (45 loc) · 1.49 KB
/
Copy pathproxy.js
File metadata and controls
49 lines (45 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
export default {
async fetch(request, env, ctx) {
const urlParam = new URL(request.url).searchParams.get("url");
if (!urlParam) {
return new Response("Missing url", { status: 400 });
}
const headers = {
"origin": "https://moviebox.ng",
"referer": "https://moviebox.ng"
};
// مرر Range وUser-Agent من الطلب الأصلي
if (request.headers.get("range")) {
headers["range"] = request.headers.get("range");
}
if (request.headers.get("user-agent")) {
headers["user-agent"] = request.headers.get("user-agent");
}
try {
const targetRes = await fetch(decodeURIComponent(urlParam), {
headers,
redirect: "manual"
});
// تمرير الهيدرات المهمة فقط
const allowed = [
"content-type", "content-length", "accept-ranges", "content-range",
"content-disposition", "cache-control", "pragma", "expires", "last-modified", "etag"
];
const respHeaders = new Headers();
for (const [key, value] of targetRes.headers.entries()) {
if (allowed.includes(key.toLowerCase())) {
respHeaders.set(key, value);
}
}
if (!respHeaders.has("content-type")) {
respHeaders.set("content-type", "video/mp4");
}
return new Response(targetRes.body, {
status: targetRes.status,
headers: respHeaders
});
} catch (e) {
return new Response("Proxy error: " + e.message, { status: 500 });
}
}
}