Skip to content

Commit dff6109

Browse files
committed
Create basic health check script
1 parent 115f5ac commit dff6109

File tree

5 files changed

+1048
-36
lines changed

5 files changed

+1048
-36
lines changed

backend/selective-entry.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,25 @@ export default {
148148
);
149149
}
150150

151+
// Basic Cloudflare health endpoint (no framework)
152+
if (pathname === "/api/cloudflare-health" && request.method === "GET") {
153+
return new workerGlobals.Response(
154+
JSON.stringify({
155+
status: "healthy",
156+
service: "cloudflare-worker",
157+
timestamp: new Date().toISOString(),
158+
deployment_env: env.DEPLOYMENT_ENV,
159+
}),
160+
{
161+
status: 200,
162+
headers: {
163+
"Content-Type": "application/json",
164+
"Access-Control-Allow-Origin": "*",
165+
},
166+
}
167+
);
168+
}
169+
151170
// CORS preflight handling
152171
if (request.method === "OPTIONS") {
153172
return new workerGlobals.Response(null, {

backend/trpc/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ export const appRouter = router({
4444
return ctx;
4545
}),
4646

47+
// Health endpoint - public
48+
health: publicProcedure.query(async (opts) => {
49+
const { ctx } = opts;
50+
return {
51+
status: "healthy",
52+
framework: "trpc",
53+
deployment_env: ctx.env.DEPLOYMENT_ENV,
54+
timestamp: new Date().toISOString(),
55+
authenticated: ctx.user !== null,
56+
user_id: ctx.user?.id || null,
57+
};
58+
}),
59+
4760
// Get current user (private data)
4861
me: authedProcedure.query(async (opts) => {
4962
const { ctx } = opts;

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
"format": "prettier --write .",
4747
"format:check": "prettier --check .",
4848
"check": "pnpm type-check && pnpm lint && pnpm format:check",
49-
"start": "echo 'Use `pnpm dev` to run the integrated server (frontend + backend). Legacy `dev:sync` script removed - now using Cloudflare Vite plugin.'"
49+
"start": "echo 'Use `pnpm dev` to run the integrated server (frontend + backend). Legacy `dev:sync` script removed - now using Cloudflare Vite plugin.'",
50+
"health": "tsx scripts/health.ts"
5051
},
5152
"dependencies": {
5253
"@codemirror/autocomplete": "^6.18.6",
@@ -178,6 +179,7 @@
178179
"prettier-plugin-tailwindcss": "^0.6.13",
179180
"rollup-plugin-visualizer": "^6.0.3",
180181
"tailwindcss": "^4.1.10",
182+
"tsx": "^4.19.2",
181183
"typescript": "^5.8.3",
182184
"vite": "^6.3.5",
183185
"vitest": "^3.0.0",

0 commit comments

Comments
 (0)