refactor(http): move to core package (#4690)

This commit is contained in:
Meier Lukas
2025-12-19 16:37:21 +01:00
committed by GitHub
parent a0a11e3570
commit 6f0dbae121
75 changed files with 280 additions and 286 deletions

View File

@@ -1,7 +1,8 @@
import { fetch } from "undici";
import { extractErrorMessage } from "@homarr/common";
import { LoggingAgent } from "@homarr/common/server";
import { UndiciHttpAgent } from "@homarr/core/infrastructure/http";
import { withTimeoutAsync } from "@homarr/core/infrastructure/http/timeout";
import { createLogger } from "@homarr/core/infrastructure/logs";
import { ErrorWithMetadata } from "@homarr/core/infrastructure/logs/error";
@@ -9,28 +10,21 @@ const logger = createLogger({ module: "ping" });
export const sendPingRequestAsync = async (url: string) => {
try {
const controller = new AbortController();
// 10 seconds timeout:
const timeoutId = setTimeout(() => controller.abort(), 10000);
const start = performance.now();
return await fetch(url, {
dispatcher: new LoggingAgent({
connect: {
rejectUnauthorized: false, // Ping should always work, even with untrusted certificates
},
}),
signal: controller.signal,
})
.finally(() => {
clearTimeout(timeoutId);
})
.then((response) => {
const end = performance.now();
const durationMs = end - start;
return { statusCode: response.status, durationMs };
return await withTimeoutAsync(async (signal) => {
return await fetch(url, {
dispatcher: new UndiciHttpAgent({
connect: {
rejectUnauthorized: false, // Ping should always work, even with untrusted certificates
},
}),
signal,
});
}).then((response) => {
const end = performance.now();
const durationMs = end - start;
return { statusCode: response.status, durationMs };
});
} catch (error) {
logger.error(new ErrorWithMetadata("Failed to send ping request", { url }, { cause: error }));
return {