fix: update endpoint for cname check (#37210)

This commit is contained in:
Kang Ming authored and GitHub committed 2025-07-17 09:28:34 +02:00
1 parent 1b7137ab10
commit 140d6026ab
5 files changed
+43 -15

No files matched your search

-2
View File
@@ -41,7 +41,6 @@ const STRIPE_SUBDOMAINS_URL = 'https://*.stripe.com'
const STRIPE_JS_URL = 'https://js.stripe.com'
const STRIPE_NETWORK_URL = 'https://*.stripe.network'
const CLOUDFLARE_URL = 'https://www.cloudflare.com'
const ONE_ONE_ONE_ONE_URL = 'https://one.one.one.one'
const VERCEL_URL = 'https://vercel.com'
const VERCEL_INSIGHTS_URL = 'https://*.vercel-insights.com'
const GITHUB_API_URL = 'https://api.github.com'
@@ -81,7 +80,6 @@ module.exports.getCSP = function getCSP() {
STRIPE_SUBDOMAINS_URL,
STRIPE_NETWORK_URL,
CLOUDFLARE_URL,
ONE_ONE_ONE_ONE_URL,
VERCEL_INSIGHTS_URL,
GITHUB_API_URL,
GITHUB_USER_CONTENT_URL,
@@ -1,5 +1,6 @@
import { useMutation, UseMutationOptions } from '@tanstack/react-query'
import { fetchHandler } from 'data/fetchers'
import { constructHeaders, fetchHandler, handleError } from 'data/fetchers'
import { BASE_PATH } from 'lib/constants'
import { toast } from 'sonner'
import type { ResponseError } from 'types'
@@ -22,19 +23,24 @@ export type CheckCNAMERecordResponse = {
// [Joshen] Should tally with https://github.com/supabase/cli/blob/63790a1bd43bee06f82c4f510e709925526a4daa/internal/utils/api.go#L98
export async function checkCNAMERecord({ domain }: CheckCNAMERecordVariables) {
const res = await fetchHandler(`https://one.one.one.one/dns-query?name=${domain}&type=CNAME`, {
method: 'GET',
headers: { accept: 'application/dns-json' },
})
const verification = (await res.json()) as CheckCNAMERecordResponse
try {
const headers = await constructHeaders({ 'Content-Type': 'application/json' })
const res: CheckCNAMERecordResponse = await fetchHandler(`${BASE_PATH}/api/check-cname`, {
headers,
method: 'POST',
body: JSON.stringify({ domain }),
}).then((res) => res.json())
if (verification.Answer === undefined) {
throw new Error(
`Your CNAME record for ${domain} cannot be found - if you've just added the record, do check back in a bit.`
)
if (res.Answer === undefined) {
throw new Error(
`Your CNAME record for ${domain} cannot be found - if you've just added the record, do check back in a bit.`
)
}
return res.Answer.some((x) => x.type === 5)
} catch (error) {
handleError(error)
}
return verification.Answer.some((x) => x.type === 5)
}
type CheckCNAMERecordData = Awaited<ReturnType<typeof checkCNAMERecord>>
+3 -1
View File
@@ -6,7 +6,8 @@ import { API_URL } from 'lib/constants'
import { getAccessToken } from 'lib/gotrue'
import { uuidv4 } from 'lib/helpers'
import { ResponseError } from 'types'
import type { paths } from './api' // generated from openapi-typescript
// generated from openapi-typescript
import type { paths } from './api'
const DEFAULT_HEADERS = { Accept: 'application/json' }
@@ -15,6 +16,7 @@ export const fetchHandler: typeof fetch = async (input, init) => {
return await fetch(input, init)
} catch (err: any) {
if (err instanceof TypeError && err.message === 'Failed to fetch') {
console.error(err)
throw new Error('Unable to reach the server. Please check your network or try again later.')
}
throw err
+1
View File
@@ -24,6 +24,7 @@ const HOSTED_SUPPORTED_API_URLS = [
'/ai/feedback/classify',
'/get-ip-address',
'/get-utc-time',
'/check-cname',
'/edge-functions/test',
'/edge-functions/body',
]
+21
View File
@@ -0,0 +1,21 @@
import { CheckCNAMERecordResponse } from 'data/custom-domains/check-cname-mutation'
import { NextApiRequest, NextApiResponse } from 'next'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const { domain } = req.body
try {
const result: CheckCNAMERecordResponse = await fetch(
`https://cloudflare-dns.com/dns-query?name=${domain}&type=CNAME`,
{
method: 'GET',
headers: { Accept: 'application/dns-json' },
}
).then((res) => res.json())
return res.status(200).json(result)
} catch (error: any) {
return res.status(400).json({ message: error.message })
}
}
export default handler