feat: add undici fetch interceptor (#687)

Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
This commit is contained in:
ManuelandMeier Lukas authored and GitHub committed 2024-06-19 19:26:42 +02:00
1 parent bf607349e0
commit 508369cb0b
4 files changed
+34 -1

No files matched your search

@@ -0,0 +1,20 @@
import type { Dispatcher } from "undici";
import { Agent, setGlobalDispatcher } from "undici";
import { logger } from "@homarr/log";
class LoggingAgent extends Agent {
constructor(...props: ConstructorParameters<typeof Agent>) {
super(...props);
}
dispatch(options: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandlers): boolean {
logger.info(
`Dispatching request ${options.method} ${options.origin as string}${options.path} (${Object.keys(options.headers as object).length} headers)`,
);
return super.dispatch(options, handler);
}
}
const agent = new LoggingAgent();
setGlobalDispatcher(agent);