forked from stardothosting/nullfake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudflare-worker-proxy.js
More file actions
76 lines (67 loc) · 2.6 KB
/
cloudflare-worker-proxy.js
File metadata and controls
76 lines (67 loc) · 2.6 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
export default {
async fetch(request, env, ctx) {
// Only allow requests from your domain
const allowedOrigins = ['https://yourdomain.com', 'https://nullfake.com'];
const origin = request.headers.get('Origin');
if (!allowedOrigins.includes(origin)) {
return new Response('Forbidden', { status: 403 });
}
// Extract ASIN from request
const url = new URL(request.url);
const asin = url.searchParams.get('asin');
if (!asin || !/^[A-Z0-9]{10}$/.test(asin)) {
return new Response('Invalid ASIN', { status: 400 });
}
// Add random delay to avoid patterns
const delay = Math.floor(Math.random() * 3000) + 1000; // 1-4 seconds
await new Promise(resolve => setTimeout(resolve, delay));
// Rotate user agents
const userAgents = [
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Safari/605.1.15'
];
const userAgent = userAgents[Math.floor(Math.random() * userAgents.length)];
try {
// Make request to Amazon
const amazonUrl = `https://www.amazon.com/dp/${asin}`;
const response = await fetch(amazonUrl, {
method: 'HEAD',
headers: {
'User-Agent': userAgent,
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate',
'DNT': '1',
'Connection': 'keep-alive',
},
});
// Return just the status code
return new Response(JSON.stringify({
asin: asin,
status_code: response.status,
timestamp: new Date().toISOString()
}), {
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': origin,
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type',
}
});
} catch (error) {
return new Response(JSON.stringify({
asin: asin,
error: error.message,
timestamp: new Date().toISOString()
}), {
status: 500,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': origin,
}
});
}
}
}