Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
fix: checker request body (#739)
Maximilian Kaskee3ba32d02bb0
diff --git a/apps/web/src/app/api/checker/test/route.ts b/apps/web/src/app/api/checker/test/route.tsindex ec49ce931..cde1df7be 100644--- a/apps/web/src/app/api/checker/test/route.ts+++ b/apps/web/src/app/api/checker/test/route.ts@@ -31,6 +31,7 @@ export async function POST(request: Request) {if (url === "https://www.openstatus.dev/api/checker/test") {return NextResponse.json({ success: true }, { status: 200 });}+const res = await checkRegion(url, region, { method, headers, body });return NextResponse.json(res);diff --git a/apps/web/src/app/play/checker/[id]/utils.ts b/apps/web/src/app/play/checker/[id]/utils.tsindex f35988a89..a412938b4 100644--- a/apps/web/src/app/play/checker/[id]/utils.ts+++ b/apps/web/src/app/play/checker/[id]/utils.ts@@ -104,7 +104,7 @@ export async function checkRegion([key]: value,};}, {}),- body: opts?.body,+ body: opts?.body ? JSON.parse(opts.body) : undefined,}),next: { revalidate: 0 },});diff --git a/apps/web/src/components/forms/monitor/form.tsx b/apps/web/src/components/forms/monitor/form.tsxindex 6c3268983..29b9d4338 100644--- a/apps/web/src/components/forms/monitor/form.tsx+++ b/apps/web/src/components/forms/monitor/form.tsx@@ -126,11 +126,32 @@ export function MonitorForm({});};- const pingEndpoint = async (region?: MonitorFlyRegion) => {- const { url, body, method, headers, statusAssertions, headerAssertions } =- form.getValues();+ const validateJSON = (value?: string) => {+ if (!value) return;+ try {+ const obj = JSON.parse(value) as Record<string, unknown>;+ form.clearErrors("body");+ return obj;+ } catch (e) {+ form.setError("body", {+ message: "Not a valid JSON object",+ });+ return false;+ }+ };+ const pingEndpoint = async (region?: MonitorFlyRegion) => {try {+ const { url, body, method, headers, statusAssertions, headerAssertions } =+ form.getValues();++ if (body && body !== "") {+ const validJSON = validateJSON(body);+ if (!validJSON) {+ return { error: "Not a valid JSON object.", data: undefined };+ }+ }+const res = await fetch(`/api/checker/test`, {method: "POST",headers: new Headers({@@ -140,6 +161,12 @@ export function MonitorForm({signal: AbortSignal.timeout(ABORT_TIMEOUT),});+ if (!res.ok) {+ return {+ error: "Something went wrong. Please try again.",+ };+ }+const as = assertions.deserialize(JSON.stringify([...(statusAssertions || []),@@ -175,6 +202,7 @@ export function MonitorForm({return { data, error: undefined };} catch (error) {+ console.error(error);if (error instanceof Error && error.name === "AbortError") {return {error: `Abort error: request takes more then ${formatDuration(diff --git a/apps/web/src/components/forms/monitor/section-requests.tsx b/apps/web/src/components/forms/monitor/section-requests.tsxindex 05da42726..2e36dedd2 100644--- a/apps/web/src/components/forms/monitor/section-requests.tsx+++ b/apps/web/src/components/forms/monitor/section-requests.tsx@@ -32,7 +32,6 @@ import {} from "@openstatus/ui";import { SectionHeader } from "../shared/section-header";-import { RequestTestButton } from "./request-test-button";interface Props {form: UseFormReturn<InsertMonitor>;@@ -207,6 +206,7 @@ export function SectionRequests({ form }: Props) {</TooltipProvider></div><FormControl>+ {/* FIXME: cannot enter 'Enter' */}<Textarearows={8}placeholder='{ "hello": "world" }'