feat: add structured JSON logger and worker utility (P1-4)

Introduces src/lib/logger.ts emitting JSON lines (level, message, data)
compatible with Cloudflare Logpush. Replaces all console.log/warn/error
calls in email-processor.ts, index.ts, and hub.ts with structured logger
calls. Extracts waitUntilSafe into src/utils/worker.ts to avoid duplicating
the executionCtx guard across routes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Julien Herr
2026-05-22 10:55:15 +02:00
parent 0c0669c473
commit a9501d6e44
5 changed files with 62 additions and 29 deletions
+4 -14
View File
@@ -1,23 +1,13 @@
import { Hono, type Context } from "hono";
import { Hono } from "hono";
import { Env } from "../types";
type AppEnv = { Bindings: Env };
import {
verifyAndStoreSubscription,
verifyAndDeleteSubscription,
} from "../utils/websub";
import { waitUntilSafe } from "../utils/worker";
import { DEFAULT_LEASE_SECONDS, MAX_LEASE_SECONDS } from "../config/constants";
function waitUntilSafe(c: Context<AppEnv>, promise: Promise<unknown>) {
// Hono throws when ExecutionContext isn't present (e.g. Node unit tests).
try {
c.executionCtx.waitUntil(promise);
} catch {
// ignore
}
}
const DEFAULT_LEASE_SECONDS = 86400;
const MAX_LEASE_SECONDS = 30 * 24 * 3600; // 30 days
type AppEnv = { Bindings: Env };
export const hubRouter = new Hono<AppEnv>();