Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

fix(nextcloud): issue with self signed certificates (#2760)

Meier Lukas7f77130978eb
diff --git a/packages/certificates/src/server.ts b/packages/certificates/src/server.ts
index 9146896e1..ad332ebd2 100644
--- a/packages/certificates/src/server.ts
+++ b/packages/certificates/src/server.ts
@@ -1,6 +1,6 @@
import fsSync from "node:fs";
import fs from "node:fs/promises";
-import { Agent } from "node:https";
+import { Agent as HttpsAgent } from "node:https";
import path from "node:path";
import { rootCertificates } from "node:tls";
import axios from "axios";
@@ -70,12 +70,16 @@ export const createCertificateAgentAsync = async () => {
});
};
-export const createAxiosCertificateInstanceAsync = async () => {
+export const createHttpsAgentAsync = async () => {
const customCertificates = await loadCustomRootCertificatesAsync();
+ return new HttpsAgent({
+ ca: rootCertificates.concat(customCertificates.map((cert) => cert.content)),
+ });
+};
+
+export const createAxiosCertificateInstanceAsync = async () => {
return axios.create({
- httpsAgent: new Agent({
- ca: rootCertificates.concat(customCertificates.map((cert) => cert.content)),
- }),
+ httpsAgent: await createHttpsAgentAsync(),
});
};
diff --git a/packages/integrations/src/nextcloud/nextcloud.integration.ts b/packages/integrations/src/nextcloud/nextcloud.integration.ts
index 7f6268a6d..b9a9e7063 100644
--- a/packages/integrations/src/nextcloud/nextcloud.integration.ts
+++ b/packages/integrations/src/nextcloud/nextcloud.integration.ts
@@ -3,7 +3,9 @@ import objectSupport from "dayjs/plugin/objectSupport";
import utc from "dayjs/plugin/utc";
import * as ical from "node-ical";
import { DAVClient } from "tsdav";
+import type { RequestInit as UndiciFetchRequestInit } from "undici";
+import { createCertificateAgentAsync } from "@homarr/certificates/server";
import { logger } from "@homarr/log";
import { Integration } from "../base/integration";
@@ -14,12 +16,12 @@ dayjs.extend(objectSupport);
export class NextcloudIntegration extends Integration {
public async testConnectionAsync(): Promise<void> {
- const client = this.createCalendarClient();
+ const client = await this.createCalendarClientAsync();
await client.login();
}
public async getCalendarEventsAsync(start: Date, end: Date): Promise<CalendarEvent[]> {
- const client = this.createCalendarClient();
+ const client = await this.createCalendarClientAsync();
await client.login();
const calendars = await client.fetchCalendars();
@@ -83,7 +85,7 @@ export class NextcloudIntegration extends Integration {
});
}
- private createCalendarClient() {
+ private async createCalendarClientAsync() {
return new DAVClient({
serverUrl: this.integration.url,
credentials: {
@@ -92,6 +94,10 @@ export class NextcloudIntegration extends Integration {
},
authMethod: "Basic",
defaultAccountType: "caldav",
+ fetchOptions: {
+ // We can use the undici options as the global fetch is used instead of the polyfilled.
+ dispatcher: await createCertificateAgentAsync(),
+ } satisfies UndiciFetchRequestInit as RequestInit,
});
}
}