refactor(dns): move to core package (#4687)
This commit is contained in:
@@ -17,7 +17,8 @@
|
||||
"./infrastructure/certificates": "./src/infrastructure/certificates/index.ts",
|
||||
"./infrastructure/certificates/hostnames/db/sqlite": "./src/infrastructure/certificates/hostnames/db/sqlite.ts",
|
||||
"./infrastructure/certificates/hostnames/db/mysql": "./src/infrastructure/certificates/hostnames/db/mysql.ts",
|
||||
"./infrastructure/certificates/hostnames/db/postgresql": "./src/infrastructure/certificates/hostnames/db/postgresql.ts"
|
||||
"./infrastructure/certificates/hostnames/db/postgresql": "./src/infrastructure/certificates/hostnames/db/postgresql.ts",
|
||||
"./infrastructure/dns/init": "./src/infrastructure/dns/init.ts"
|
||||
},
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
@@ -36,6 +37,7 @@
|
||||
"dependencies": {
|
||||
"@t3-oss/env-nextjs": "^0.13.8",
|
||||
"better-sqlite3": "^12.5.0",
|
||||
"dns-caching": "^0.2.9",
|
||||
"drizzle-orm": "^0.45.1",
|
||||
"ioredis": "5.8.2",
|
||||
"mysql2": "3.15.3",
|
||||
|
||||
8
packages/core/src/infrastructure/dns/env.ts
Normal file
8
packages/core/src/infrastructure/dns/env.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { createBooleanSchema, createEnv } from "../env";
|
||||
|
||||
export const dnsEnv = createEnv({
|
||||
server: {
|
||||
ENABLE_DNS_CACHING: createBooleanSchema(false),
|
||||
},
|
||||
experimental__runtimeEnv: process.env,
|
||||
});
|
||||
28
packages/core/src/infrastructure/dns/init.ts
Normal file
28
packages/core/src/infrastructure/dns/init.ts
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user