-
Notifications
You must be signed in to change notification settings - Fork 65
/
index.js
44 lines (41 loc) · 1.28 KB
/
index.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
const doh = 'https://security.cloudflare-dns.com/dns-query'
const dohjson = 'https://security.cloudflare-dns.com/dns-query'
const contype = 'application/dns-message'
const jstontype = 'application/dns-json'
export const onRequestGet = async ({request}) => {
const { method, headers, url } = request
const searchParams = new URL(url).searchParams
if (searchParams.has('dns')) {
return await fetch(doh + '?dns=' + searchParams.get('dns'), {
method: 'GET',
headers: {
'Accept': contype,
}
});
} else if (method== 'GET' && headers.get('Accept')==jstontype) {
const search = new URL(url).search
return await fetch(dohjson + search, {
method: 'GET',
headers: {
'Accept': jstontype,
}
});
} else {
return new Response("", {status: 404})
}
}
export const onRequestPost = async ({ request }) => {
const { headers } = request
if (headers.get('content-type')==contype) {
return fetch(doh, {
method: 'POST',
headers: {
'Accept': contype,
'Content-Type': contype,
},
body: request.body,
});
} else {
return new Response("", {status: 404})
}
}