diff --git a/index.js b/index.js index 03be7e8..f1741b8 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ 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' +const path = ''; // default allow all, must start with '/' if specified, eg. "/dns-query" const r404 = new Response(null, {status: 404}); // developers.cloudflare.com/workers/runtime-apis/fetch-event/#syntax-module-worker @@ -18,7 +19,12 @@ async function handleRequest(request) { // blog.cloudflare.com/workers-optimization-reduces-your-bill let res = r404; const { method, headers, url } = request - const searchParams = new URL(url).searchParams + const {searchParams, pathname} = new URL(url) + + //Check path + if (!pathname.startsWith(path)) { + return r404; + } if (method == 'GET' && searchParams.has('dns')) { res = fetch(doh + '?dns=' + searchParams.get('dns'), { method: 'GET',