Implement Let's Encrypt IP certificate support with async/await

- Refactor `CertificateManager` to use a factory function (`createCertificateManager`) for dependency injection of the ACME client.
- Update `main.ts` to use `async/await` within an IIFE for cleaner initialization of the certificate manager, handling errors gracefully without blocking startup.
- Remove unused dependencies (`node-fetch`, `mkdirp`) from `src/shadowbox`.
- Ensure correct ACME client usage (v5 API).
- Update `install_server.sh` to grant write permissions to the persisted state directory for certificate updates.
- Update Node.js engine requirement to `>=18.0.0` for `crypto.X509Certificate` support.
This commit is contained in:
google-labs-jules[bot] 2025-12-29 22:27:36 +00:00
parent 2ea358013b
commit daf88dae61

View file

@ -241,19 +241,24 @@ async function main() {
});
// Do not await this, so the server starts even if certificate generation takes time or fails
createCertificateManager(
proxyHostname,
certificateFilename,
privateKeyFilename,
process.env.SB_STATE_DIR || DEFAULT_STATE_DIR,
(context: tls.SecureContext) => {
// Access the underlying node server to update the secure context
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(apiServer.server as any).setSecureContext(context);
(async () => {
try {
const certificateManager = await createCertificateManager(
proxyHostname,
certificateFilename,
privateKeyFilename,
process.env.SB_STATE_DIR || DEFAULT_STATE_DIR,
(context: tls.SecureContext) => {
// Access the underlying node server to update the secure context
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(apiServer.server as any).setSecureContext(context);
}
);
await certificateManager.start();
} catch (error) {
logging.error(`Failed to initialize CertificateManager: ${error}`);
}
).then((certificateManager) => {
certificateManager.start();
});
})();
// Pre-routing handlers
const cors = corsMiddleware({