mirror of
https://github.com/juherr/kill-the-news.git
synced 2026-06-20 22:03:48 +00:00
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:
+4
-14
@@ -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>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user