Skip to content

The Open Source DocuSign Alternative.

fix: incorrect certificate health logic (#2028)

Lucas Smith32ce573de402
diff --git a/apps/remix/app/routes/api+/health.ts b/apps/remix/app/routes/api+/health.ts
index 1ebdfbadb..c43ac1478 100644
--- a/apps/remix/app/routes/api+/health.ts
+++ b/apps/remix/app/routes/api+/health.ts
@@ -23,10 +23,12 @@ export const loader = async () => {
try {
const certStatus = getCertificateStatus();
+
if (certStatus.isAvailable) {
checks.certificate = { status: 'ok' };
} else {
checks.certificate = { status: 'warning' };
+
if (overallStatus === 'ok') {
overallStatus = 'warning';
}
diff --git a/packages/lib/server-only/cert/cert-status.ts b/packages/lib/server-only/cert/cert-status.ts
index cf5387dcd..ad0e336bd 100644
--- a/packages/lib/server-only/cert/cert-status.ts
+++ b/packages/lib/server-only/cert/cert-status.ts
@@ -2,18 +2,25 @@ import * as fs from 'node:fs';
import { env } from '@documenso/lib/utils/env';
-export type CertificateStatus = {
- isAvailable: boolean;
-};
+export const getCertificateStatus = () => {
+ if (env('NEXT_PRIVATE_SIGNING_TRANSPORT') !== 'local') {
+ return { isAvailable: true };
+ }
+
+ if (env('NEXT_PRIVATE_SIGNING_LOCAL_FILE_CONTENTS')) {
+ return { isAvailable: true };
+ }
-export const getCertificateStatus = (): CertificateStatus => {
const defaultPath =
env('NODE_ENV') === 'production' ? '/opt/documenso/cert.p12' : './example/cert.p12';
+
const filePath = env('NEXT_PRIVATE_SIGNING_LOCAL_FILE_PATH') || defaultPath;
try {
fs.accessSync(filePath, fs.constants.F_OK | fs.constants.R_OK);
+
const stats = fs.statSync(filePath);
+
return { isAvailable: stats.size > 0 };
} catch {
return { isAvailable: false };