-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathworkers.js
63 lines (54 loc) · 1.94 KB
/
workers.js
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
addEventListener('fetch', event => {
event.respondWith(handle(event.request))
})
async function handle(request) {
const urlPath = new URL(request.url).pathname
const urlQuery = new URL(request.url).searchParams.get('var')
if(urlPath == "/" && urlQuery == null){
let ip_address = { ip : request.headers.get("cf-connecting-ip"),}
return new Response(JSON.stringify(ip_address), {
status: 200,
headers: {
"Access-Control-Allow-Origin": "*",
"content-type": "application/json;charset=UTF-8",
"dev": "https://github.com/prabha-coder",
"deployed-at": "cloudflare"
},
})
}
else if(urlPath=="/ip" && urlQuery == null){
let ip_address = request.headers.get("cf-connecting-ip")
return new Response('document.write("' + ip_address + '");', {
status: 200,
headers: {
"Access-Control-Allow-Origin": "*",
"content-type": "application/json;charset=UTF-8",
"dev": "https://github.com/prabha-coder",
"deployed-at": "cloudflare"
},
})
}
else if(urlQuery){
let ip_address = request.headers.get("cf-connecting-ip")
return new Response(urlQuery + ' = "' + ip_address + '";', {
status: 200,
headers: {
"Access-Control-Allow-Origin": "*",
"content-type": "text/html;charset=UTF-8",
"dev": "https://github.com/prabha-coder",
"deployed-at": "cloudflare"
},
})
}
else{
return new Response("Bad Request",{
status: 400,
headers: {
"Access-Control-Allow-Origin": "*",
"content-type": "text/html;charset=UTF-8",
"dev": "https://github.com/prabha-coder",
"deployed-at": "cloudflare"
},
})
}
}