refactor(dns): move to core package (#4687)

This commit is contained in:
Meier Lukas
2025-12-19 09:55:41 +01:00
committed by GitHub
parent 2b971b9392
commit f4bb90013a
7 changed files with 17 additions and 11 deletions

View File

@@ -0,0 +1,8 @@
import { createBooleanSchema, createEnv } from "../env";
export const dnsEnv = createEnv({
server: {
ENABLE_DNS_CACHING: createBooleanSchema(false),
},
experimental__runtimeEnv: process.env,
});

View File

@@ -0,0 +1,28 @@
import { DnsCacheManager } from "dns-caching";
import { createLogger } from "@homarr/core/infrastructure/logs";
import { dnsEnv } from "./env";
// Add global type augmentation for homarr
declare global {
var homarr: {
dnsCacheManager?: DnsCacheManager;
// add other properties if needed
};
}
const logger = createLogger({ module: "dns" });
// Initialize global.homarr if not present
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
global.homarr ??= {};
global.homarr.dnsCacheManager ??= new DnsCacheManager({
cacheMaxEntries: 1000,
forceMinTtl: 5 * 60 * 1000, // 5 minutes
logger,
});
if (dnsEnv.ENABLE_DNS_CACHING) {
global.homarr.dnsCacheManager.initialize();
}