Skip to content

Commit fc80ba1

Browse files
committed
fix: read Caddy certificates for same-VPS setup
1 parent 4ff5443 commit fc80ba1

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ services:
5858
volumes:
5959
- ./logs:/app/logs
6060
- ./backups:/app/backups
61+
- caddy_data:/caddy_data:ro
6162
env_file:
6263
- .env
6364
environment:

src/services/nodeSetup.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,34 @@ const Settings = require('../models/settingsModel');
1212
const configGenerator = require('./configGenerator');
1313

1414
/**
15-
* Read panel's SSL certificates from Greenlock directory
15+
* Read panel's SSL certificates from Greenlock or Caddy directory
1616
* @param {string} domain - Panel domain
1717
* @returns {Object|null} { cert, key } or null if not found
1818
*/
1919
function getPanelCertificates(domain) {
2020
try {
21-
// Greenlock stores certificates in greenlock.d/live/{domain}/
22-
const greenlockDir = path.join(__dirname, '../../greenlock.d/live', domain);
21+
let cert, key;
22+
23+
// Try Caddy certificates first (when USE_CADDY=true)
24+
// Caddy stores certs in /caddy_data/caddy/certificates/acme-v02.api.letsencrypt.org-directory/{domain}/
25+
const caddyDir = path.join('/caddy_data/caddy/certificates/acme-v02.api.letsencrypt.org-directory', domain);
26+
const caddyCertPath = path.join(caddyDir, `${domain}.crt`);
27+
const caddyKeyPath = path.join(caddyDir, `${domain}.key`);
28+
29+
if (fs.existsSync(caddyCertPath) && fs.existsSync(caddyKeyPath)) {
30+
cert = fs.readFileSync(caddyCertPath, 'utf8');
31+
key = fs.readFileSync(caddyKeyPath, 'utf8');
32+
logger.info(`[NodeSetup] Found Caddy certificates for ${domain}`);
33+
return { cert, key };
34+
}
2335

36+
// Try Greenlock certificates (when USE_CADDY is not set)
37+
// Greenlock stores certs in greenlock.d/live/{domain}/
38+
const greenlockDir = path.join(__dirname, '../../greenlock.d/live', domain);
2439
const certPath = path.join(greenlockDir, 'cert.pem');
2540
const keyPath = path.join(greenlockDir, 'privkey.pem');
26-
27-
// Also try fullchain.pem if cert.pem doesn't exist
2841
const fullchainPath = path.join(greenlockDir, 'fullchain.pem');
2942

30-
let cert, key;
31-
3243
if (fs.existsSync(certPath)) {
3344
cert = fs.readFileSync(certPath, 'utf8');
3445
} else if (fs.existsSync(fullchainPath)) {
@@ -40,11 +51,11 @@ function getPanelCertificates(domain) {
4051
}
4152

4253
if (cert && key) {
43-
logger.info(`[NodeSetup] Found panel certificates for ${domain}`);
54+
logger.info(`[NodeSetup] Found Greenlock certificates for ${domain}`);
4455
return { cert, key };
4556
}
4657

47-
logger.warn(`[NodeSetup] Panel certificates not found in ${greenlockDir}`);
58+
logger.warn(`[NodeSetup] Panel certificates not found (checked Caddy: ${caddyDir}, Greenlock: ${greenlockDir})`);
4859
return null;
4960

5061
} catch (error) {

0 commit comments

Comments
 (0)