Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
chore: improve custom-domain configuration (#2046)
Maximilian Kaske7a478c4ba034
diff --git a/apps/dashboard/src/components/domains/domain-configuration.tsx b/apps/dashboard/src/components/domains/domain-configuration.tsxindex 1f236b7d1..4a713c038 100644--- a/apps/dashboard/src/components/domains/domain-configuration.tsx+++ b/apps/dashboard/src/components/domains/domain-configuration.tsx@@ -10,9 +10,17 @@ import {import { cn } from "@openstatus/ui/lib/utils";import { Note } from "@/components/common/note";+import {+ StepCard,+ StepCardBadge,+ StepCardContent,+ StepCardHeader,+ StepCardIndicator,+ StepCardTitle,+} from "@/components/forms/step-card";import { getSubdomain } from "@/lib/domains";import { CircleCheck } from "lucide-react";-import DomainStatusIcon from "./domain-status-icon";+import { DomainStatusIcon } from "./domain-status-icon";import { useDomainStatus } from "./use-domain-status";export const InlineSnippet = ({@@ -34,20 +42,17 @@ export const InlineSnippet = ({);};+const CNAME_VALUE =+ process.env.NEXT_PUBLIC_VERCEL_PROJECT_DNS_CNAME || "cname.vercel-dns.com";+const A_RECORD_VALUE =+ process.env.NEXT_PUBLIC_VERCEL_PROJECT_DNS_A || "76.76.21.21";+// FIXME: add loading state!export default function DomainConfiguration({ domain }: { domain: string }) {- const { status, domainJson, isLoading } = useDomainStatus(domain);+ const { status, domainJson, steps, isLoading } = useDomainStatus(domain);if (!status || !domainJson) return null;- if (status === "Valid Configuration")- return (- <Note color="success">- <CircleCheck />- Your domain is configured and you can use it to access your status page.- </Note>- );-const subdomain =domainJson?.name && domainJson?.apexName? getSubdomain(domainJson.name, domainJson.apexName)@@ -59,114 +64,171 @@ export default function DomainConfiguration({ domain }: { domain: string }) {null;return (- <div>- <div className="mb-4 flex items-center space-x-2">+ <div className="space-y-3">+ <div className="flex items-center space-x-2"><DomainStatusIcon status={status} loading={isLoading} />- <p className="font-semibold">{status}</p>+ <p className="font-semibold text-sm">{status}</p><Badge variant="secondary">{domain}</Badge></div>- {txtVerification ? (- <>- <p className="text-sm">- Please set the following TXT record on{" "}- <InlineSnippet>{domainJson.apexName}</InlineSnippet> to prove- ownership of <InlineSnippet>{domainJson.name}</InlineSnippet>:- </p>- <div className="my-5 flex items-start justify-start space-x-10 rounded-md bg-muted p-2">- <div>- <p className="font-bold text-sm">Type</p>- <p className="mt-2 font-mono text-sm">{txtVerification.type}</p>- </div>- <div>- <p className="font-bold text-sm">Name</p>- <p className="mt-2 font-mono text-sm">- {txtVerification.domain.slice(- 0,- txtVerification.domain.length -- (domainJson?.apexName?.length || 0) -- 1,- )}- </p>- </div>- <div>- <p className="font-bold text-sm">Value</p>- <p className="mt-2 font-mono text-sm">- <span className="text-ellipsis">{txtVerification.value}</span>++ {/* Step 1: DNS Configuration */}+ <StepCard variant={steps.dns}>+ <StepCardHeader>+ <StepCardIndicator step={1} />+ <StepCardTitle>Configure DNS records</StepCardTitle>+ <StepCardBadge>Done</StepCardBadge>+ </StepCardHeader>+ <StepCardContent>+ {status === "Unknown Error" ? (+ <p className="text-sm">{domainJson?.error?.message}</p>+ ) : (+ <>+ <Tabs defaultValue={subdomain ? "CNAME" : "A"}>+ <TabsList>+ <TabsTrigger value="A">+ A Record{!subdomain && " (recommended)"}+ </TabsTrigger>+ <TabsTrigger value="CNAME">+ CNAME Record{subdomain && " (recommended)"}+ </TabsTrigger>+ </TabsList>+ <TabsContent value="A" className="space-y-2">+ <p className="text-sm">+ To configure your apex domain (+ <InlineSnippet>{domainJson.apexName}</InlineSnippet>+ ), set the following A record on your DNS provider:+ </p>+ <div className="flex items-center justify-start space-x-10 rounded-md bg-muted p-2">+ <div>+ <p className="font-bold text-sm">Type</p>+ <p className="mt-2 font-mono text-sm">A</p>+ </div>+ <div>+ <p className="font-bold text-sm">Name</p>+ <p className="mt-2 font-mono text-sm">@</p>+ </div>+ <div>+ <p className="font-bold text-sm">Value</p>+ <p className="mt-2 font-mono text-sm">{A_RECORD_VALUE}</p>+ </div>+ <div>+ <p className="font-bold text-sm">TTL</p>+ <p className="mt-2 font-mono text-sm">86400</p>+ </div>+ </div>+ </TabsContent>+ <TabsContent value="CNAME">+ <div className="flex items-center justify-start space-x-10 rounded-md bg-muted p-2">+ <div>+ <p className="font-bold text-sm">Type</p>+ <p className="mt-2 font-mono text-sm">CNAME</p>+ </div>+ <div>+ <p className="font-bold text-sm">Name</p>+ <p className="mt-2 font-mono text-sm">+ {subdomain ?? "www"}+ </p>+ </div>+ <div>+ <p className="font-bold text-sm">Value</p>+ <p className="mt-2 font-mono text-sm">{CNAME_VALUE}</p>+ </div>+ <div>+ <p className="font-bold text-sm">TTL</p>+ <p className="mt-2 font-mono text-sm">86400</p>+ </div>+ </div>+ </TabsContent>+ </Tabs>+ <p className="mt-3 text-muted-foreground text-sm">+ Note: for TTL, if <InlineSnippet>86400</InlineSnippet> is not+ available, set the highest value possible. Domain propagation+ can take up to an hour.</p>- </div>- </div>- <p className="text-muted-foreground text-sm">- Warning: if you are using this domain for another site, setting this- TXT record will transfer domain ownership away from that site and- break it. Please exercise caution when setting this record.- </p>- </>- ) : status === "Unknown Error" ? (- <p className="mb-5 text-sm">{domainJson?.error?.message}</p>- ) : (- <>- <Tabs defaultValue={subdomain ? "CNAME" : "A"}>- <TabsList>- <TabsTrigger value="A">- A Record{!subdomain && " (recommended)"}- </TabsTrigger>- <TabsTrigger value="CNAME">- CNAME Record{subdomain && " (recommended)"}- </TabsTrigger>- </TabsList>- <TabsContent value="A" className="space-y-2">+ </>+ )}+ </StepCardContent>+ </StepCard>++ {/* Step 2: Domain Verification */}+ <StepCard variant={steps.verification}>+ <StepCardHeader>+ <StepCardIndicator step={2} />+ <StepCardTitle>Verify domain ownership</StepCardTitle>+ <StepCardBadge>Done</StepCardBadge>+ </StepCardHeader>+ <StepCardContent>+ {txtVerification ? (+ <><p className="text-sm">- To configure your apex domain (- <InlineSnippet>{domainJson.apexName}</InlineSnippet>- ), set the following A record on your DNS provider to continue:+ Set the following TXT record on{" "}+ <InlineSnippet>{domainJson.apexName}</InlineSnippet> to prove+ ownership of <InlineSnippet>{domainJson.name}</InlineSnippet>:</p>- <div className="flex items-center justify-start space-x-10 rounded-md bg-muted p-2">+ <div className="my-3 flex items-start justify-start space-x-10 rounded-md bg-muted p-2"><div><p className="font-bold text-sm">Type</p>- <p className="mt-2 font-mono text-sm">A</p>+ <p className="mt-2 font-mono text-sm">+ {txtVerification.type}+ </p></div><div><p className="font-bold text-sm">Name</p>- <p className="mt-2 font-mono text-sm">@</p>+ <p className="mt-2 font-mono text-sm">+ {txtVerification.domain.slice(+ 0,+ txtVerification.domain.length -+ (domainJson?.apexName?.length || 0) -+ 1,+ )}+ </p></div><div><p className="font-bold text-sm">Value</p>- <p className="mt-2 font-mono text-sm">76.76.21.21</p>- </div>- <div>- <p className="font-bold text-sm">TTL</p>- <p className="mt-2 font-mono text-sm">86400</p>+ <p className="mt-2 break-all font-mono text-sm">+ {txtVerification.value}+ </p></div></div>- </TabsContent>- <TabsContent value="CNAME">- <div className="flex items-center justify-start space-x-10 rounded-md bg-muted p-2">- <div>- <p className="font-bold text-sm">Type</p>- <p className="mt-2 font-mono text-sm">CNAME</p>- </div>- <div>- <p className="font-bold text-sm">Name</p>- <p className="mt-2 font-mono text-sm">{subdomain ?? "www"}</p>- </div>- <div>- <p className="font-bold text-sm">Value</p>- <p className="mt-2 font-mono text-sm">cname.vercel-dns.com</p>- </div>- <div>- <p className="font-bold text-sm">TTL</p>- <p className="mt-2 font-mono text-sm">86400</p>- </div>- </div>- </TabsContent>- </Tabs>- <p className="muted-foreground mt-5 text-sm">- Note: for TTL, if <InlineSnippet>86400</InlineSnippet> is not- available, set the highest value possible. Also, domain propagation- can take up to an hour.- </p>- </>- )}+ <p className="text-muted-foreground text-sm">+ Warning: if you are using this domain for another site, setting+ this TXT record will transfer domain ownership away from that+ site and break it. Please exercise caution when setting this+ record.+ </p>+ </>+ ) : (+ <p className="text-muted-foreground text-sm">+ A TXT record may be required to verify domain ownership. The exact+ record values will appear here once DNS is configured.+ </p>+ )}+ </StepCardContent>+ </StepCard>++ {/* Step 3: Ready */}+ <StepCard variant={steps.ready}>+ <StepCardHeader>+ <StepCardIndicator step={3} />+ <StepCardTitle>Ready</StepCardTitle>+ <StepCardBadge>Done</StepCardBadge>+ </StepCardHeader>+ <StepCardContent>+ {steps.ready === "completed" ? (+ <Note color="success">+ <CircleCheck />+ Your domain is configured and you can use it to access your status+ page.+ </Note>+ ) : (+ <p className="text-muted-foreground text-sm">+ Your status page will be live at{" "}+ <InlineSnippet>{domain}</InlineSnippet> once the steps above are+ complete.+ </p>+ )}+ </StepCardContent>+ </StepCard></div>);}diff --git a/apps/dashboard/src/components/domains/domain-status-icon.tsx b/apps/dashboard/src/components/domains/domain-status-icon.tsxindex b1444729f..e41f48d07 100644--- a/apps/dashboard/src/components/domains/domain-status-icon.tsx+++ b/apps/dashboard/src/components/domains/domain-status-icon.tsx@@ -4,7 +4,7 @@ import { AlertCircle, CheckCircle2, LoaderCircle, XCircle } from "lucide-react";import type { DomainVerificationStatusProps } from "@openstatus/api/src/router/domain";-export default function DomainStatusIcon({+export function DomainStatusIcon({status,loading,}: {@@ -13,22 +13,26 @@ export default function DomainStatusIcon({}) {return loading ? (<LoaderCircle- className="animate-spin text-muted-foreground"+ className="size-6 animate-spin text-muted-foreground"stroke="currentColor"/>) : status === "Valid Configuration" ? (<CheckCircle2- fill="#22c55e"+ fill="var(--color-success)"stroke="currentColor"- className="text-background"+ className="size-6 text-background"/>) : status === "Pending Verification" ? (<AlertCircle- fill="#eab308"+ fill="var(--color-warning)"stroke="currentColor"- className="text-background"+ className="size-6 text-background"/>) : (- <XCircle fill="#ef4444" stroke="currentColor" className="text-background" />+ <XCircle+ fill="var(--color-destructive)"+ stroke="currentColor"+ className="size-6 text-background"+ />);}diff --git a/apps/dashboard/src/components/domains/use-domain-status.ts b/apps/dashboard/src/components/domains/use-domain-status.tsindex 120dc1c75..9fdaf75d9 100644--- a/apps/dashboard/src/components/domains/use-domain-status.ts+++ b/apps/dashboard/src/components/domains/use-domain-status.ts@@ -1,5 +1,6 @@import type { DomainVerificationStatusProps } from "@openstatus/api/src/router/domain";+import type { StepCardVariant } from "@/components/forms/step-card";import { useTRPC } from "@/lib/trpc/client";import { useQuery } from "@tanstack/react-query";import { useCallback } from "react";@@ -60,16 +61,36 @@ export function useDomainStatus(domain?: string) {status = "Valid Configuration";}+ const isLoading =+ isLoadingDomain ||+ isLoadingConfig ||+ isLoadingVerification ||+ isRefetchingDomain ||+ isRefetchingConfig ||+ isRefetchingVerification;++ const steps = {+ dns:+ status === "Valid Configuration" || status === "Pending Verification"+ ? "completed"+ : "active",+ verification:+ status === "Valid Configuration"+ ? "completed"+ : status === "Pending Verification"+ ? "active"+ : // "Invalid Configuration" means DNS is misconfigured but ownership is verified+ status === "Invalid Configuration"+ ? "completed"+ : "upcoming",+ ready: status === "Valid Configuration" ? "completed" : "upcoming",+ } satisfies Record<string, StepCardVariant>;+return {status,domainJson,+ steps,refresh: refreshAll,- isLoading:- isLoadingDomain ||- isLoadingConfig ||- isLoadingVerification ||- isRefetchingDomain ||- isRefetchingConfig ||- isRefetchingVerification,+ isLoading,};}diff --git a/apps/dashboard/src/components/forms/step-card.tsx b/apps/dashboard/src/components/forms/step-card.tsxnew file mode 100644index 000000000..764b1c7fc--- /dev/null+++ b/apps/dashboard/src/components/forms/step-card.tsx@@ -0,0 +1,160 @@+import {+ Card,+ CardContent,+ CardHeader,+ CardTitle,+} from "@openstatus/ui/components/ui/card";+import { cn } from "@openstatus/ui/lib/utils";++import { Badge } from "@openstatus/ui/components/ui/badge";+import { type VariantProps, cva } from "class-variance-authority";+import { Check } from "lucide-react";++export type StepCardVariant = NonNullable<+ VariantProps<typeof stepCardVariants>["variant"]+>;++const stepCardVariants = cva(+ "group relative w-full overflow-hidden py-0 gap-0 shadow-none",+ {+ variants: {+ variant: {+ active: "border-border bg-background",+ completed: "border-success/30 bg-success/5",+ upcoming: "border-border/50 bg-muted/30",+ },+ },+ defaultVariants: {+ variant: "active",+ },+ },+);++export function StepCard({+ children,+ className,+ variant,+ ...props+}: React.ComponentProps<"div"> & VariantProps<typeof stepCardVariants>) {+ return (+ <Card+ data-variant={variant ?? "active"}+ className={cn(stepCardVariants({ variant }), className)}+ {...props}+ >+ {children}+ </Card>+ );+}++export function StepCardHeader({+ children,+ className,+ ...props+}: React.ComponentProps<"div">) {+ return (+ <CardHeader+ data-slot="step-card-header"+ className={cn("flex flex-row items-center gap-3 px-4 py-3", className)}+ {...props}+ >+ {children}+ </CardHeader>+ );+}++export function StepCardIndicator({+ step,+ className,+ ...props+}: React.ComponentProps<"div"> & { step: number }) {+ return (+ <div+ data-slot="step-card-indicator"+ role="img"+ aria-label={`Step ${step}`}+ className={cn(+ "flex h-6 w-6 shrink-0 items-center justify-center rounded-full font-medium text-xs",+ "group-data-[variant=completed]:bg-success group-data-[variant=completed]:text-white",+ "group-data-[variant=active]:border group-data-[variant=active]:border-foreground group-data-[variant=active]:bg-background group-data-[variant=active]:text-foreground",+ "group-data-[variant=upcoming]:border group-data-[variant=upcoming]:border-border group-data-[variant=upcoming]:bg-muted group-data-[variant=upcoming]:text-muted-foreground",+ className,+ )}+ {...props}+ >+ <span+ aria-hidden="true"+ className="group-data-[variant=completed]:hidden"+ >+ {step}+ </span>+ <Check+ aria-hidden="true"+ className="hidden h-3 w-3 group-data-[variant=completed]:block"+ />+ </div>+ );+}++export function StepCardTitle({+ children,+ className,+ ...props+}: React.ComponentProps<"div">) {+ return (+ <CardTitle+ data-slot="step-card-title"+ className={cn(+ "text-sm",+ "group-data-[variant=completed]:text-success",+ "group-data-[variant=upcoming]:text-muted-foreground",+ className,+ )}+ {...props}+ >+ {children}+ </CardTitle>+ );+}++export function StepCardBadge({+ children,+ className,+ ...props+}: Omit<React.ComponentProps<typeof Badge>, "variant">) {+ return (+ <Badge+ data-slot="step-card-badge"+ variant="secondary"+ className={cn(+ "hidden group-data-[variant=completed]:inline-flex",+ "bg-success/10 text-success",+ className,+ )}+ {...props}+ >+ {children}+ </Badge>+ );+}++export function StepCardContent({+ children,+ className,+ ...props+}: React.ComponentProps<"div">) {+ return (+ <CardContent+ data-slot="step-card-content"+ className={cn(+ "px-4 pb-4",+ "group-data-[variant=completed]:hidden",+ "group-data-[variant=upcoming]:select-none group-data-[variant=upcoming]:opacity-50",+ className,+ )}+ {...props}+ >+ {children}+ </CardContent>+ );+}diff --git a/packages/api/src/router/page.ts b/packages/api/src/router/page.tsindex 4e5442a30..1b64d83ef 100644--- a/packages/api/src/router/page.ts+++ b/packages/api/src/router/page.ts@@ -26,7 +26,7 @@ if (process.env.NODE_ENV === "test") {// Helper functions to reuse Vercel API logicasync function addDomainToVercel(domain: string) {- const data = await fetch(+ const response = await fetch(`https://api.vercel.com/v9/projects/${env.PROJECT_ID_VERCEL}/domains?teamId=${env.TEAM_ID_VERCEL}`,{body: JSON.stringify({ name: domain }),@@ -37,11 +37,22 @@ async function addDomainToVercel(domain: string) {method: "POST",},);- return data.json();++ if (!response.ok) {+ const error = await response.json().catch(() => ({}));+ console.error("Failed to add domain to Vercel:", { domain, error });+ throw new TRPCError({+ code: "INTERNAL_SERVER_ERROR",+ message:+ "Failed to add custom domain. Please try again. If it continues, contact support.",+ });+ }++ return response.json();}async function removeDomainFromVercel(domain: string) {- const data = await fetch(+ const response = await fetch(`https://api.vercel.com/v9/projects/${env.PROJECT_ID_VERCEL}/domains/${domain}?teamId=${env.TEAM_ID_VERCEL}`,{headers: {@@ -50,7 +61,18 @@ async function removeDomainFromVercel(domain: string) {method: "DELETE",},);- return data.json();++ if (!response.ok) {+ const error = await response.json().catch(() => ({}));+ console.error("Failed to remove domain from Vercel:", { domain, error });+ throw new TRPCError({+ code: "INTERNAL_SERVER_ERROR",+ message:+ "Failed to remove custom domain. Please try again. If it continues, contact support.",+ });+ }++ return response.json();}export const pageRouter = createTRPCRouter({@@ -385,59 +407,44 @@ export const pageRouter = createTRPCRouter({const oldDomain = currentPage.customDomain;const newDomain = opts.input.customDomain;- try {- // Handle domain changes- if (newDomain && !oldDomain) {- // Adding a new domain- await opts.ctx.db- .update(page)- .set({ customDomain: newDomain, updatedAt: new Date() })- .where(and(...whereConditions))- .run();-- // Add domain to Vercel using the domain router logic- await addDomainToVercel(newDomain);- } else if (oldDomain && newDomain !== oldDomain) {- // Changing domain - remove old and add new- await opts.ctx.db- .update(page)- .set({ customDomain: newDomain, updatedAt: new Date() })- .where(and(...whereConditions))- .run();-- // Remove old domain from Vercel- await removeDomainFromVercel(oldDomain);-- // Add new domain to Vercel- if (newDomain) {- await addDomainToVercel(newDomain);- }- } else if (oldDomain && newDomain === "") {- // Removing domain- await opts.ctx.db- .update(page)- .set({ customDomain: "", updatedAt: new Date() })- .where(and(...whereConditions))- .run();-- // Remove domain from Vercel- await removeDomainFromVercel(oldDomain);- } else {- // No change needed, just update the database- await opts.ctx.db- .update(page)- .set({ customDomain: newDomain, updatedAt: new Date() })- .where(and(...whereConditions))- .run();- }- } catch (error) {- // If Vercel operations fail, we should rollback the database change- // For now, we'll just throw the error- console.error("Error updating custom domain:", error);- throw new TRPCError({- code: "INTERNAL_SERVER_ERROR",- message: "Failed to update custom domain",- });+ // Vercel operations first — if they fail, DB is not touched+ if (newDomain && !oldDomain) {+ // Adding a new domain+ await addDomainToVercel(newDomain);++ await opts.ctx.db+ .update(page)+ .set({ customDomain: newDomain, updatedAt: new Date() })+ .where(and(...whereConditions))+ .run();+ } else if (oldDomain && newDomain && newDomain !== oldDomain) {+ // Changing domain - add new first, then remove old+ await addDomainToVercel(newDomain);+ await removeDomainFromVercel(oldDomain);++ await opts.ctx.db+ .update(page)+ .set({ customDomain: newDomain, updatedAt: new Date() })+ .where(and(...whereConditions))+ .run();+ } else if (oldDomain && newDomain === "") {+ // Removing domain+ await removeDomainFromVercel(oldDomain);++ await opts.ctx.db+ .update(page)+ .set({ customDomain: "", updatedAt: new Date() })+ .where(and(...whereConditions))+ .run();+ } else if (newDomain) {+ // Same domain re-submitted — ensure it's synced to Vercel+ await addDomainToVercel(newDomain);++ await opts.ctx.db+ .update(page)+ .set({ customDomain: newDomain, updatedAt: new Date() })+ .where(and(...whereConditions))+ .run();}}),