- Add `app` export and wrap startup logic behind `if (import.meta.main)` - Extract `hono` middleware into `sdk/hono.ts` for clean separation - Refactor module imports slightly to support in-memory native mocking (`db`, `valkey`, `spire_ffi`, `ratelimit`, `audit`) - Implement comprehensive native Deno mock tests in `server/main.test.ts` - Fix type checking across project files Co-authored-by: mrteye <1945243+mrteye@users.noreply.github.com>
30 lines
808 B
TypeScript
30 lines
808 B
TypeScript
import { Redis } from "npm:ioredis";
|
|
|
|
const VALKEY_URL = Deno.env.get("VALKEY_URL") ||
|
|
(import.meta.main ? "redis://auth-valkey:6379" : "");
|
|
|
|
export const valkey = VALKEY_URL
|
|
? new Redis(VALKEY_URL, {
|
|
enableOfflineQueue: false,
|
|
})
|
|
: {} as Redis; // Mock for tests
|
|
|
|
export async function pingValkey(): Promise<void> {
|
|
if (!VALKEY_URL) return; // Skip in test
|
|
try {
|
|
const result = await valkey.ping();
|
|
if (result !== "PONG") {
|
|
throw new Error(`Unexpected ping response: ${result}`);
|
|
}
|
|
} catch (error) {
|
|
if (error instanceof Error) {
|
|
throw new Error(
|
|
`Fatal: Failed to connect to Valkey session cache. Halting boot. ${error.message}`,
|
|
);
|
|
}
|
|
throw new Error(
|
|
`Fatal: Failed to connect to Valkey session cache. Halting boot.`,
|
|
);
|
|
}
|
|
}
|