mirror of
https://github.com/LittleChest/Dohna-NS.git
synced 2026-08-05 12:16:15 +08:00
handler: Refactor
This commit is contained in:
parent
1b6191580d
commit
0d95560738
@ -1,4 +1,4 @@
|
|||||||
import handler from "./common";
|
import handler from "./handler/dns";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
fetch: async (request, env) =>
|
fetch: async (request, env) =>
|
||||||
|
|||||||
@ -45,19 +45,16 @@ export default async function handler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { method, headers, url } = request;
|
const { method, headers, url } = request;
|
||||||
const { search, searchParams, pathname } = new URL(url);
|
const { search, searchParams } = new URL(url);
|
||||||
|
|
||||||
const ip =
|
const ip =
|
||||||
rawIP ||
|
rawIP ||
|
||||||
headers.get("x-forwarded-for").split(",")[0].trim() ||
|
headers.get("x-forwarded-for").split(",")[0].trim() ||
|
||||||
headers.get("x-real-ip");
|
headers.get("x-real-ip");
|
||||||
|
|
||||||
let res = new Response(null, { status: 404 });
|
let res = new Response(null, { status: 400 });
|
||||||
|
|
||||||
// JSON API
|
// JSON API
|
||||||
if (pathname === "/resolve") {
|
|
||||||
res = new Response(null, { status: 400 });
|
|
||||||
|
|
||||||
if (method === "GET" && searchParams.has("name")) {
|
if (method === "GET" && searchParams.has("name")) {
|
||||||
if (concurrent) {
|
if (concurrent) {
|
||||||
res = await Promise.any(
|
res = await Promise.any(
|
||||||
@ -101,12 +98,8 @@ export default async function handler(
|
|||||||
res = new Response(null, { status: 500 });
|
res = new Response(null, { status: 500 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// DNS Query
|
// DNS Query
|
||||||
if (pathname === "/dns-query") {
|
|
||||||
res = new Response(null, { status: 400 });
|
|
||||||
|
|
||||||
let queryData;
|
let queryData;
|
||||||
|
|
||||||
// GET
|
// GET
|
||||||
@ -158,7 +151,6 @@ export default async function handler(
|
|||||||
concurrent,
|
concurrent,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
19
handler/entrypoint.js
Normal file
19
handler/entrypoint.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import dnsHandler from "./dns";
|
||||||
|
|
||||||
|
export default async function handler(
|
||||||
|
request,
|
||||||
|
dns,
|
||||||
|
api,
|
||||||
|
ipv4Prefix = 32,
|
||||||
|
ipv6Prefix = 128,
|
||||||
|
concurrent = false,
|
||||||
|
rawIP,
|
||||||
|
) {
|
||||||
|
const { pathname } = new URL(request.url);
|
||||||
|
let res = new Response(null, { status: 404 });
|
||||||
|
|
||||||
|
// DNS over HTTPS & JSON API
|
||||||
|
if (pathname === "/dns-query" || pathname === "/resolve") {
|
||||||
|
res = dnsHandler(request, dns, api, ipv4Prefix, ipv6Prefix, concurrent, rawIP);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import handler from "./common";
|
import handler from "./handler/dns";
|
||||||
|
|
||||||
export default middleware = async (request) => {
|
export default middleware = async (request) => {
|
||||||
return handler(
|
return handler(
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import handler from "../../common.js";
|
import handler from "../../handler/dns.js";
|
||||||
export default async (request) =>
|
export default async (request) =>
|
||||||
handler(
|
handler(
|
||||||
request,
|
request,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user