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

@@ -24,12 +24,10 @@ export const env = createEnv({
message: `SECRET_ENCRYPTION_KEY must only contain hex characters${errorSuffix}`,
}),
NO_EXTERNAL_CONNECTION: createBooleanSchema(false),
ENABLE_DNS_CACHING: createBooleanSchema(false),
},
runtimeEnv: {
SECRET_ENCRYPTION_KEY: process.env.SECRET_ENCRYPTION_KEY,
NODE_ENV: process.env.NODE_ENV,
NO_EXTERNAL_CONNECTION: process.env.NO_EXTERNAL_CONNECTION,
ENABLE_DNS_CACHING: process.env.ENABLE_DNS_CACHING,
},
});

View File

@@ -8,7 +8,6 @@
".": "./index.ts",
"./types": "./src/types.ts",
"./server": "./src/server.ts",
"./init-dns": "./src/dns.ts",
"./client": "./src/client.ts",
"./env": "./env.ts"
},
@@ -30,7 +29,6 @@
"@homarr/core": "workspace:^0.1.0",
"@paralleldrive/cuid2": "^3.1.0",
"dayjs": "^1.11.19",
"dns-caching": "^0.2.9",
"next": "16.0.10",
"octokit": "^5.0.5",
"react": "19.2.3",

View File

@@ -1,28 +0,0 @@
import { DnsCacheManager } from "dns-caching";
import { createLogger } from "@homarr/core/infrastructure/logs";
import { env } 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 (env.ENABLE_DNS_CACHING) {
global.homarr.dnsCacheManager.initialize();
}

View File

@@ -4,7 +4,7 @@ import { Agent } from "undici";
import { createLogger } from "@homarr/core/infrastructure/logs";
// The below import statement initializes dns-caching
import "./dns";
import "@homarr/core/infrastructure/dns/init";
const logger = createLogger({ module: "fetchAgent" });