Files
sendou.ink/app/features/dev-tools/dev-tools-server-hooks.server.ts
Kalle f7372324fe
Some checks failed
E2E Tests / e2e (push) Has been cancelled
Tests and checks on push / run-checks-and-tests (push) Has been cancelled
Updates translation progress / update-translation-progress-issue (push) Has been cancelled
E2E Tests / publish-docs-screenshots (push) Has been cancelled
Dev tools (#3471)
2026-10-25 11:43:36 +02:00

28 lines
1.1 KiB
TypeScript

import type { LogEvent } from "kysely";
import type { MiddlewareFunction } from "react-router";
import * as RequestLog from "./core/RequestLog.server";
import * as ServerConsole from "./core/ServerConsole.server";
export interface DevToolsServerHooks {
/** Records each request's database queries and the server's console errors. */
middleware: MiddlewareFunction<Response>;
/** Records a query against the request being handled, from the database's log hook. */
recordQuery: (event: LogEvent) => void;
/** Logs an error React Router reports outside the request's async context with that request attached. */
logRequestError: (request: Request, log: () => void) => void;
}
/**
* Everything the server calls in the dev tools. Production builds resolve this module to
* `dev-tools-server-hooks.stub.ts` (`vite.config.ts`), so `null` there and none of the dev tools bundled.
*/
export const devToolsServerHooks: DevToolsServerHooks | null = {
middleware: ({ request }, next) => {
ServerConsole.install();
return RequestLog.track(request, next);
},
recordQuery: RequestLog.recordQuery,
logRequestError: ServerConsole.withRequest,
};