mirror of
https://github.com/andwati/dokploy.git
synced 2026-10-18 03:02:56 +00:00
fix(requests): guard RequestHost before filtering to avoid crash on malformed logs
This commit is contained in:
@@ -55,6 +55,28 @@ describe("processLogs", () => {
|
|||||||
expect(result.data).toHaveLength(2);
|
expect(result.data).toHaveLength(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should not throw when filtering by hostname and an entry has no RequestHost", () => {
|
||||||
|
const entryWithoutRequestHost = sampleLogEntry.replace(
|
||||||
|
/"RequestHost":"[^"]*",/,
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
|
||||||
|
const mixedEntries = `${sampleLogEntry}\n${entryWithoutRequestHost}`;
|
||||||
|
|
||||||
|
expect(() =>
|
||||||
|
parseRawConfig(mixedEntries, undefined, undefined, "traefik.me"),
|
||||||
|
).not.toThrow();
|
||||||
|
|
||||||
|
const result = parseRawConfig(
|
||||||
|
mixedEntries,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
"traefik.me",
|
||||||
|
);
|
||||||
|
expect(result.totalCount).toBe(1);
|
||||||
|
expect(result.data[0]?.RequestHost).toBe("s222-umami-c381af.traefik.me");
|
||||||
|
});
|
||||||
|
|
||||||
it("should filter out Dokploy dashboard requests", () => {
|
it("should filter out Dokploy dashboard requests", () => {
|
||||||
const dokployDashboardEntry = `{"ClientAddr":"172.71.187.131:9485","ClientHost":"172.71.187.131","ClientPort":"9485","ClientUsername":"-","DownstreamContentSize":14550,"DownstreamStatus":200,"Duration":57681682,"OriginContentSize":14550,"OriginDuration":57612242,"OriginStatus":200,"Overhead":69440,"RequestAddr":"hostinger.dokploy.com","RequestContentSize":0,"RequestCount":20142,"RequestHost":"hostinger.dokploy.com","RequestMethod":"GET","RequestPath":"/_next/data/cb_zzI4Rp9G7Q7djrFKh0/en/dashboard/traefik.json","RequestPort":"-","RequestProtocol":"HTTP/2.0","RequestScheme":"https","RetryAttempts":0,"RouterName":"dokploy-router-app-secure@file","ServiceAddr":"dokploy:3000","ServiceName":"dokploy-service-app@file","ServiceURL":"http://dokploy:3000","StartLocal":"2025-12-10T05:10:41.957755949Z","StartUTC":"2025-12-10T05:10:41.957755949Z","TLSCipher":"TLS_AES_128_GCM_SHA256","TLSVersion":"1.3","entryPointName":"websecure","level":"info","msg":"","time":"2025-12-10T05:10:42Z"}`;
|
const dokployDashboardEntry = `{"ClientAddr":"172.71.187.131:9485","ClientHost":"172.71.187.131","ClientPort":"9485","ClientUsername":"-","DownstreamContentSize":14550,"DownstreamStatus":200,"Duration":57681682,"OriginContentSize":14550,"OriginDuration":57612242,"OriginStatus":200,"Overhead":69440,"RequestAddr":"hostinger.dokploy.com","RequestContentSize":0,"RequestCount":20142,"RequestHost":"hostinger.dokploy.com","RequestMethod":"GET","RequestPath":"/_next/data/cb_zzI4Rp9G7Q7djrFKh0/en/dashboard/traefik.json","RequestPort":"-","RequestProtocol":"HTTP/2.0","RequestScheme":"https","RetryAttempts":0,"RouterName":"dokploy-router-app-secure@file","ServiceAddr":"dokploy:3000","ServiceName":"dokploy-service-app@file","ServiceURL":"http://dokploy:3000","StartLocal":"2025-12-10T05:10:41.957755949Z","StartUTC":"2025-12-10T05:10:41.957755949Z","TLSCipher":"TLS_AES_128_GCM_SHA256","TLSVersion":"1.3","entryPointName":"websecure","level":"info","msg":"","time":"2025-12-10T05:10:42Z"}`;
|
||||||
|
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ export function parseRawConfig(
|
|||||||
|
|
||||||
if (search) {
|
if (search) {
|
||||||
parsedLogs = parsedLogs.filter((log) =>
|
parsedLogs = parsedLogs.filter((log) =>
|
||||||
log.RequestHost.toLowerCase().includes(search.toLowerCase()),
|
(log.RequestHost ?? "").toLowerCase().includes(search.toLowerCase()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user