feat: set 5 reties for dns query

This commit is contained in:
DIYgod
2023-03-22 19:06:08 +00:00
parent 132df6025f
commit c29f0d5ad5
2 changed files with 24 additions and 22 deletions
+22 -11
View File
@@ -720,19 +720,30 @@ export async function getMiraBalance(characterId: string, contract: Contract) {
return result
}
export async function checkDomainServer(domain: string, handle: string) {
const dns = await (
await fetch(
`https://cloudflare-dns.com/dns-query?name=_xlog-challenge.${domain}&type=TXT`,
{
headers: {
accept: "application/dns-json",
},
export async function fetchTenant(
host: string,
retries: number,
): Promise<string> {
const res = await fetch(
`https://cloudflare-dns.com/dns-query?name=_xlog-challenge.${host}&type=TXT`,
{
headers: {
accept: "application/dns-json",
},
)
).json()
},
)
const txt = await res.json()
if (txt.Status === 5 && retries > 0) {
console.log("retrying", host, retries - 1)
return await fetchTenant(host, retries - 1)
} else {
return txt?.Answer?.[0]?.data.replace(/^"|"$/g, "")
}
}
export async function checkDomainServer(domain: string, handle: string) {
const tenant = await fetchTenant(domain, 5)
const tenant = dns?.Answer?.[0]?.data.replace(/^"|"$/g, "")
if (!tenant || tenant !== handle) {
return false
} else {
+2 -11
View File
@@ -1,7 +1,7 @@
import { NextApiRequest, NextApiResponse } from "next"
import { OUR_DOMAIN } from "~/lib/env"
import { cacheGet } from "~/lib/redis.server"
import { checkDomainServer } from "~/models/site.model"
import { checkDomainServer, fetchTenant } from "~/models/site.model"
export default async function handler(
req: NextApiRequest,
@@ -48,16 +48,7 @@ export default async function handler(
}
}
} else {
const res = await fetch(
`https://cloudflare-dns.com/dns-query?name=_xlog-challenge.${realHost}&type=TXT`,
{
headers: {
accept: "application/dns-json",
},
},
)
const txt = await res.json()
const tenant = txt?.Answer?.[0]?.data.replace(/^"|"$/g, "")
const tenant = await fetchTenant(realHost, 5)
return {
subdomain: tenant,
}