fix(docs): Improve certificate manager documentation with detailed examples and custom implementation guide
This commit is contained in:
48
readme.md
48
readme.md
@ -113,6 +113,54 @@ const certManager = new MongoCertManager({
|
||||
});
|
||||
```
|
||||
|
||||
SmartAcme uses the `ICertManager` interface for certificate storage. Two built-in implementations are available:
|
||||
|
||||
- **MemoryCertManager**
|
||||
- In-memory storage, suitable for testing or ephemeral use.
|
||||
- Import example:
|
||||
```typescript
|
||||
import { MemoryCertManager } from '@push.rocks/smartacme';
|
||||
const certManager = new MemoryCertManager();
|
||||
```
|
||||
|
||||
- **MongoCertManager**
|
||||
- Persistent storage in MongoDB (collection: `SmartacmeCert`).
|
||||
- Import example:
|
||||
```typescript
|
||||
import { MongoCertManager } from '@push.rocks/smartacme';
|
||||
const certManager = new MongoCertManager({
|
||||
mongoDbUrl: 'mongodb://yourmongoURL',
|
||||
mongoDbName: 'yourDbName',
|
||||
mongoDbPass: 'yourDbPassword',
|
||||
});
|
||||
```
|
||||
|
||||
#### Custom Certificate Managers
|
||||
|
||||
To implement a custom certificate manager, implement the `ICertManager` interface and pass it to `SmartAcme`:
|
||||
|
||||
```typescript
|
||||
import type { ICertManager, Cert as SmartacmeCert } from '@push.rocks/smartacme';
|
||||
import { SmartAcme } from '@push.rocks/smartacme';
|
||||
|
||||
class MyCustomCertManager implements ICertManager {
|
||||
async init(): Promise<void> { /* setup storage */ }
|
||||
async get(domainName: string): Promise<SmartacmeCert | null> { /* lookup cert */ }
|
||||
async put(cert: SmartacmeCert): Promise<SmartacmeCert> { /* store cert */ }
|
||||
async delete(domainName: string): Promise<void> { /* remove cert */ }
|
||||
async close?(): Promise<void> { /* optional cleanup */ }
|
||||
}
|
||||
|
||||
// Use your custom manager:
|
||||
const customManager = new MyCustomCertManager();
|
||||
const smartAcme = new SmartAcme({
|
||||
accountEmail: 'youremail@example.com',
|
||||
certManager: customManager,
|
||||
environment: 'integration',
|
||||
challengeHandlers: [], // add your handlers
|
||||
});
|
||||
```
|
||||
|
||||
### Environmental Considerations
|
||||
|
||||
When creating an instance of `SmartAcme`, you can specify an `environment` option. This is particularly useful for testing, as you can use the `integration` environment to avoid hitting rate limits and for testing your setup without issuing real certificates. Switch to `production` when you are ready to obtain actual certificates.
|
||||
|
Reference in New Issue
Block a user