-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcf_worker_dynupdate-without-authorization.js
More file actions
35 lines (32 loc) · 1.11 KB
/
cf_worker_dynupdate-without-authorization.js
File metadata and controls
35 lines (32 loc) · 1.11 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
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
/**
* Validate dynamic update request and update API if passed
*/
async function handleRequest(request) {
const clientIP = request.headers.get("CF-Connecting-IP")
var url = "https://api.cloudflare.com/client/v4/zones/{fill in zone-ID}/dns_records/{fill in DNS_record-ID}"
var Body = {
"zone_name": "example.com", //your zone name goes here
"name": "apple", //the DNS record to be updated
"type": "A", // the type of record
"content": clientIP,
"proxied": false,
"ttl": 60 // changing to more optimum value without taxing AuthDNS
}
var myHeaders = new Headers()
myHeaders.append('Content-Type', 'application/json;charset=UTF-8')
myHeaders.append('X-Auth-Key', API_KEY) //using predefined Environment variable
myHeaders.append('X-Auth-Email', EMAIL) //using predefined Environment variable
var init = {
body: JSON.stringify(Body),
method: "PUT",
headers: myHeaders
}
//if (decode == test) {
const response = await fetch(url, init)
console.log(response)
return new Response(response.body)
// }
}