fix: add dns caching (#3736)
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
".": "./index.ts",
|
||||
"./types": "./src/types.ts",
|
||||
"./server": "./src/server.ts",
|
||||
"./init-dns": "./src/dns.ts",
|
||||
"./client": "./src/client.ts",
|
||||
"./env": "./env.ts"
|
||||
},
|
||||
@@ -30,6 +31,7 @@
|
||||
"@homarr/log": "workspace:^0.1.0",
|
||||
"@paralleldrive/cuid2": "^2.2.2",
|
||||
"dayjs": "^1.11.15",
|
||||
"dns-caching": "^0.2.5",
|
||||
"next": "15.5.2",
|
||||
"react": "19.1.1",
|
||||
"react-dom": "19.1.1",
|
||||
|
||||
22
packages/common/src/dns.ts
Normal file
22
packages/common/src/dns.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { DnsCacheManager } from "dns-caching";
|
||||
|
||||
import { logger } from "@homarr/log";
|
||||
|
||||
// Add global type augmentation for homarr
|
||||
declare global {
|
||||
var homarr: {
|
||||
dnsCacheManager?: DnsCacheManager;
|
||||
// add other properties if needed
|
||||
};
|
||||
}
|
||||
|
||||
// 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,
|
||||
});
|
||||
|
||||
global.homarr.dnsCacheManager.initialize();
|
||||
@@ -3,6 +3,9 @@ import { Agent } from "undici";
|
||||
|
||||
import { logger } from "@homarr/log";
|
||||
|
||||
// The below import statement initializes dns-caching
|
||||
import "./dns";
|
||||
|
||||
export class LoggingAgent extends Agent {
|
||||
constructor(...props: ConstructorParameters<typeof Agent>) {
|
||||
super(...props);
|
||||
|
||||
Reference in New Issue
Block a user