mirror of
https://github.com/LittleChest/Dohna-NS.git
synced 2026-06-21 04:48:44 +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 {
|
||||
fetch: async (request, env) =>
|
||||
|
||||
@ -45,19 +45,16 @@ export default async function handler(
|
||||
}
|
||||
|
||||
const { method, headers, url } = request;
|
||||
const { search, searchParams, pathname } = new URL(url);
|
||||
const { search, searchParams } = new URL(url);
|
||||
|
||||
const ip =
|
||||
rawIP ||
|
||||
headers.get("x-forwarded-for").split(",")[0].trim() ||
|
||||
headers.get("x-real-ip");
|
||||
|
||||
let res = new Response(null, { status: 404 });
|
||||
let res = new Response(null, { status: 400 });
|
||||
|
||||
// JSON API
|
||||
if (pathname === "/resolve") {
|
||||
res = new Response(null, { status: 400 });
|
||||
|
||||
if (method === "GET" && searchParams.has("name")) {
|
||||
if (concurrent) {
|
||||
res = await Promise.any(
|
||||
@ -101,12 +98,8 @@ export default async function handler(
|
||||
res = new Response(null, { status: 500 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DNS Query
|
||||
if (pathname === "/dns-query") {
|
||||
res = new Response(null, { status: 400 });
|
||||
|
||||
let queryData;
|
||||
|
||||
// GET
|
||||
@ -158,7 +151,6 @@ export default async function handler(
|
||||
concurrent,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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) => {
|
||||
return handler(
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import handler from "../../common.js";
|
||||
import handler from "../../handler/dns.js";
|
||||
export default async (request) =>
|
||||
handler(
|
||||
request,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user