Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IS_PLATFORM } from 'common'
import { NextApiRequest, NextApiResponse } from 'next'
import { NextResponse } from 'next/server'

import { InternalServerError } from '@/lib/api/apiHelpers'
import { getActiveIncidents, type IncidentCache } from '@/lib/api/incident-status'
Expand Down Expand Up @@ -42,22 +42,26 @@ async function fetchIncidentCache(incidentIds: Array<string>): Promise<Map<strin
return cacheMap
}

async function handler(req: NextApiRequest, res: NextApiResponse) {
if (!IS_PLATFORM) {
return res.status(404).end()
}
export async function OPTIONS() {
if (!IS_PLATFORM) return new Response(null, { status: 404 })
return new Response(null, {
status: 204,
headers: {
Allow: 'GET, HEAD, OPTIONS',
},
})
}

const { method } = req
export async function HEAD() {
if (!IS_PLATFORM) return new Response(null, { status: 404 })
return new Response(null, {
status: 200,
headers: { 'Cache-Control': CACHE_CONTROL_SETTINGS },
})
}

if (method === 'HEAD') {
res.setHeader('Cache-Control', CACHE_CONTROL_SETTINGS)
return res.status(200).end()
}

if (method !== 'GET') {
res.setHeader('Allow', ['GET', 'HEAD'])
return res.status(405).json({ error: `Method ${method} Not Allowed` })
}
export async function GET() {
if (!IS_PLATFORM) return new Response(null, { status: 404 })

try {
const allIncidents = await getActiveIncidents()
Expand All @@ -75,17 +79,18 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
cache: cacheMap.get(incident.id) ?? null,
}))

res.setHeader('Cache-Control', CACHE_CONTROL_SETTINGS)

return res.status(200).json(enrichedIncidents)
return NextResponse.json(enrichedIncidents, {
headers: { 'Cache-Control': CACHE_CONTROL_SETTINGS },
})
} catch (error) {
let errorCode = 500
const headers = new Headers()

if (error instanceof InternalServerError) {
if (typeof error.details?.status === 'number') errorCode = error.details.status
if (errorCode === 420) errorCode = 429
if (errorCode === 429 && typeof error.details?.retryAfter === 'string') {
res.setHeader('Retry-After', error.details.retryAfter)
headers.set('Retry-After', error.details.retryAfter)
}
console.error('Failed to fetch active StatusPage incidents: %O', {
message: error.message,
Expand All @@ -95,8 +100,9 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
console.error('Unexpected error fetching active StatusPage incidents: %O', error)
}

return res.status(errorCode).json({ error: 'Unable to fetch incidents at this time' })
return NextResponse.json(
{ error: 'Unable to fetch incidents at this time' },
{ status: errorCode, headers }
)
}
}

export default handler
4 changes: 2 additions & 2 deletions apps/studio/components/grid/SupabaseGrid.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ export function useSyncTableEditorStateFromLocalStorageWithUrl({
// Use nextjs useSearchParams to get the latest URL params
const searchParams = useSearchParams()
const urlParams = useMemo(() => {
const sort = searchParams.getAll('sort')
const filter = searchParams.getAll('filter')
const sort = searchParams?.getAll('sort') ?? []
const filter = searchParams?.getAll('filter') ?? []
return { sort, filter }
}, [searchParams])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const UpgradingState = () => {
{
projectRef: ref,
projectStatus: project?.status,
trackingId: queryParams.get('trackingId'),
trackingId: queryParams?.get('trackingId'),
},
{
enabled: IS_PLATFORM,
Expand Down
5 changes: 2 additions & 3 deletions apps/studio/lib/api/incident-status.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import z from 'zod'

import { IS_PLATFORM } from 'common'
import { InternalServerError } from 'lib/api/apiHelpers'
import z from 'zod'

export type IncidentCache = {
affected_regions: Array<string> | null
Expand Down Expand Up @@ -81,7 +80,7 @@ export async function getActiveIncidents(): Promise<IncidentInfo[]> {
Accept: 'application/json',
'Content-Type': 'application/json',
},
cache: 'no-store',
next: { revalidate: 180 },
signal: AbortSignal.timeout(30_000),
})
const responseText = await response.text()
Expand Down
2 changes: 1 addition & 1 deletion apps/studio/pages/project/[ref]/sql/quickstarts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { NextPageWithLayout } from 'types'

const SqlQuickstarts: NextPageWithLayout = () => {
const router = useRouter()
const { ref } = useParams<{ ref: string }>()
const ref = useParams<{ ref: string }>()?.ref
const tabs = useTabsStateSnapshot()

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion apps/studio/pages/project/[ref]/sql/templates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { NextPageWithLayout } from 'types'

const SqlTemplates: NextPageWithLayout = () => {
const router = useRouter()
const { ref } = useParams<{ ref: string }>()
const ref = useParams<{ ref: string }>()?.ref
const tabs = useTabsStateSnapshot()

useEffect(() => {
Expand Down
3 changes: 2 additions & 1 deletion apps/studio/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"**/*.js",
"**/*.jsx",
".next/types/**/*.ts",
"./../../packages/ui/src/**/*.d.ts"
"./../../packages/ui/src/**/*.d.ts",
".next/dev/types/**/*.ts"
],
"exclude": ["node_modules", "public/deno/*.ts"]
}
Loading