rwsdk
Version:
Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime
57 lines (56 loc) • 3.19 kB
JavaScript
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import { HealthCheckClient } from "./HealthCheckClient";
export const HealthCheckInfo = async () => {
const timestamp = Date.now();
let status = "error";
let verificationPassed = false;
let result = null;
try {
result = await globalThis.__rw.callServer("__health", [timestamp]);
// Check the result
if (typeof result === "object" && result !== null) {
status = result.status || "error";
verificationPassed = result.timestamp === timestamp;
}
else if (result === "ok") {
status = "ok";
verificationPassed = true;
}
}
catch (error) {
console.error("Health check failed:", error);
status = "error";
result = { error: error instanceof Error ? error.message : String(error) };
}
return (_jsxs("div", { id: "health-check-container", style: {
fontFamily: "system-ui, -apple-system, sans-serif",
margin: "20px",
padding: "15px",
border: "1px solid #ddd",
borderRadius: "4px",
background: "#f9f9f9",
}, children: [_jsxs("h2", { style: {
color: status === "ok" ? "#0c9" : "#f44",
margin: "0 0 10px 0",
}, children: ["Health Check: ", status] }), _jsx("div", { id: "health-check-result", "data-result": status, "data-timestamp": timestamp, "data-verified": verificationPassed ? "true" : "false", children: verificationPassed
? "Timestamp verification passed ✅"
: "Timestamp verification failed ⚠️" }), _jsxs("details", { style: { marginTop: "10px" }, children: [_jsx("summary", { children: "Details" }), _jsx("pre", { style: {
background: "#f5f5f5",
padding: "10px",
borderRadius: "4px",
fontSize: "12px",
overflow: "auto",
}, children: JSON.stringify({ timestamp, result, verificationPassed }, null, 2) })] }), _jsx(HealthCheckClient, {})] }));
};
/**
* Wrapper component that displays health check info above the original page content
*/
export const HealthCheckWrapper = ({ children }) => {
return (_jsxs(_Fragment, { children: [_jsx(HealthCheckInfo, {}), children] }));
};
/**
* Standalone health check page that conforms to the RouteComponent type
*/
export const HealthCheckPage = (requestInfo) => {
return (_jsxs("div", { style: { maxWidth: "800px", margin: "0 auto", padding: "40px 20px" }, children: [_jsx("h1", { children: "RedwoodJS SDK Health Check" }), _jsx(HealthCheckInfo, {}), _jsx("p", { style: { marginTop: "20px" }, children: "This is a dedicated health check page to verify that your RedwoodJS SDK application is functioning correctly. It tests that server-side rendering, client-side hydration, and RSC (React Server Components) actions are all working properly." }), _jsx("p", { children: "Use the button below to manually trigger a new health check at any time." })] }));
};