Skip to content

Commit 65c6a68

Browse files
authored
Make check-cname endpoint GET, and improve middleware checking (supabase#37235)
1 parent 96875d6 commit 65c6a68

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

apps/studio/data/custom-domains/check-cname-mutation.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useMutation, UseMutationOptions } from '@tanstack/react-query'
2-
import { constructHeaders, fetchHandler, handleError } from 'data/fetchers'
2+
import { fetchHandler, handleError } from 'data/fetchers'
33
import { BASE_PATH } from 'lib/constants'
44
import { toast } from 'sonner'
55

@@ -24,12 +24,9 @@ export type CheckCNAMERecordResponse = {
2424
// [Joshen] Should tally with https://github.com/supabase/cli/blob/63790a1bd43bee06f82c4f510e709925526a4daa/internal/utils/api.go#L98
2525
export async function checkCNAMERecord({ domain }: CheckCNAMERecordVariables) {
2626
try {
27-
const headers = await constructHeaders({ 'Content-Type': 'application/json' })
28-
const res: CheckCNAMERecordResponse = await fetchHandler(`${BASE_PATH}/api/check-cname`, {
29-
headers,
30-
method: 'POST',
31-
body: JSON.stringify({ domain }),
32-
}).then((res) => res.json())
27+
const res: CheckCNAMERecordResponse = await fetchHandler(
28+
`${BASE_PATH}/api/check-cname?domain=${domain}`
29+
).then((res) => res.json())
3330

3431
if (res.Answer === undefined) {
3532
throw new Error(

apps/studio/middleware.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ const HOSTED_SUPPORTED_API_URLS = [
3030
]
3131

3232
export function middleware(request: NextRequest) {
33-
if (IS_PLATFORM && !HOSTED_SUPPORTED_API_URLS.some((url) => request.url.endsWith(url))) {
33+
if (
34+
IS_PLATFORM &&
35+
!HOSTED_SUPPORTED_API_URLS.some((url) => request.nextUrl.pathname.endsWith(url))
36+
) {
3437
return Response.json(
3538
{ success: false, message: 'Endpoint not supported on hosted' },
3639
{ status: 404 }

apps/studio/pages/api/check-cname.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { CheckCNAMERecordResponse } from 'data/custom-domains/check-cname-mutati
22
import { NextApiRequest, NextApiResponse } from 'next'
33

44
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
5-
const { domain } = req.body
5+
const { domain } = req.query
66

77
try {
88
const result: CheckCNAMERecordResponse = await fetch(

0 commit comments

Comments
 (0)