Skip to content

Commit 147a901

Browse files
committed
Fix bugs in file saving & in-memory ACME cert caching
1 parent 93c8d9e commit 147a901

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/tls-certificates/cert-cache.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ export class PersistentCertCache {
3131
certFiles.map(f => `'${f}'`).join(', ')
3232
}`);
3333

34-
await Promise.all(certFiles.map(async (certPath) => {
35-
if (!certPath.endsWith('.cert.json')) {
36-
console.log(`Unexpected file in cert dir: ${certPath}`);
34+
await Promise.all(certFiles.map(async (certName) => {
35+
if (!certName.endsWith('.cert.json')) {
36+
console.log(`Unexpected file in cert dir: ${certName}`);
3737
return;
3838
}
3939

40+
const certPath = path.join(this.certCacheDir, certName);
41+
4042
try {
4143
const data = JSON.parse(
4244
(await fs.readFile(certPath)).toString('utf8')
@@ -51,13 +53,16 @@ export class PersistentCertCache {
5153

5254
this.cache[data.domain] = data;
5355
} catch (e) {
54-
console.log(`Could not load cert from ${certPath}:`, e);
56+
console.log(`Could not load cert from ${certName}:`, e);
5557
}
5658
}));
5759
}
5860

5961
cacheCert(cert: CachedCertificate): CachedCertificate | undefined {
6062
const { domain } = cert;
63+
64+
this.cache[domain] = cert;
65+
6166
fs.writeFile(
6267
path.join(this.certCacheDir, `${domain}.cert.json`),
6368
JSON.stringify(cert)

0 commit comments

Comments
 (0)