CertsManager
TLS certificate management with ACME (Let's Encrypt) integration and automatic cert renewal.
Usage
import { CertsManager } from "@io-oidis-localhost/Io/Oidis/Localhost/Utils/CertsManager.js";
const certs : CertsManager = CertsManager.getInstance();
Or with explicit domain and config:
import { CertsManager } from "@io-oidis-localhost/Io/Oidis/Localhost/Utils/CertsManager.js";
import { IServerConfigurationSSL } from "@io-oidis-localhost/Io/Oidis/Localhost/Interfaces/IProject.js";
const certs : CertsManager = new CertsManager("example.com", {
certificatePath: "/path/to/cert.crt",
privateKeyPath: "/path/to/privkey.pem"
});
API Reference
Create
Registers or renews a TLS certificate for the configured domain via the ACME protocol. In production mode, checks cert validity first and only calls register when renewal is needed. In debug mode, always generates against the staging ACME endpoint.
public Create($callback : ($status : boolean, $cert? : string, $key? : string) => void) : void
$callback— called withtrueand the PEM cert/key strings on success, orfalseon failure.
getStoragePath
Returns the ACME challenge webroot path used during domain validation.
public getStoragePath() : string
// Returns: {appDataPath}/resource/data/acme-challenge
getCertPaths
Resolves and returns the IServerConfigurationSSL object with absolute paths to the certificate and private key files. Searches binBase and targetBase as fallback locations. Result is memoized after the first call.
public getCertPaths() : IServerConfigurationSSL
Configuration
The ACME endpoint is selected based on the debug flag:
| Mode | Endpoint |
|---|---|
| Production | https://acme-v02.api.letsencrypt.org/directory |
| Debug | https://acme-staging-v02.api.letsencrypt.org/directory |
Certificate email and domain are read from the project configuration (IProject.certs.mail, IProject.domain.location).
When domain.ssl is an object (IServerConfigurationSSL), the cert and key paths are used directly. When it is a string, it is treated as a base directory and the cert is resolved as {domain}_{tld}.crt / .key or fullchain.pem / privkey.pem.
See also: Utilities Overview | Commons Config | Localhost Overview