feat(handlers): Add in-memory HTTP-01 challenge handler and rename file-based handler to Http01Webroot

This commit is contained in:
2025-04-30 14:55:03 +00:00
parent 9f66a0487f
commit fc420eb615
9 changed files with 204 additions and 14 deletions

View File

@ -61,7 +61,7 @@ const smartAcmeInstance = new SmartAcme({
retryOptions: {}, // optional retry/backoff settings
challengeHandlers: [
new Dns01Handler(cfAccount),
// you can add more handlers, e.g. Http01Handler
// you can add more handlers, e.g. Http01Webroot
],
challengePriority: ['dns-01'], // optional ordering of challenge types
});
@ -143,7 +143,7 @@ async function main() {
## Built-in Challenge Handlers
This module includes two out-of-the-box ACME challenge handlers:
This module includes three out-of-the-box ACME challenge handlers:
- **Dns01Handler**
- Uses a Cloudflare account (from `@apiclient.xyz/cloudflare`) and Smartdns client to set and remove DNS TXT records, then wait for propagation.
@ -158,18 +158,31 @@ async function main() {
const dnsHandler = new Dns01Handler(cfAccount);
```
- **Http01Handler**
- **Http01Webroot**
- Writes ACME HTTP-01 challenge files under a file-system webroot (`/.well-known/acme-challenge/`), and removes them on cleanup.
- Import path:
```typescript
import { Http01Handler } from '@push.rocks/smartacme/ts/handlers/Http01Handler.js';
import { Http01Webroot } from '@push.rocks/smartacme/ts/handlers/Http01Handler.js';
```
- Example:
```typescript
const httpHandler = new Http01Handler({ webroot: '/var/www/html' });
const httpHandler = new Http01Webroot({ webroot: '/var/www/html' });
```
Both handlers implement the `IChallengeHandler<T>` interface and can be combined in the `challengeHandlers` array.
- **Http01MemoryHandler**
- In-memory HTTP-01 challenge handler that stores and serves ACME tokens without disk I/O.
- Import path:
```typescript
import { Http01MemoryHandler } from '@push.rocks/smartacme/ts/handlers/Http01MemoryHandler.js';
```
- Example (Express integration):
```typescript
import { Http01MemoryHandler } from '@push.rocks/smartacme/ts/handlers/Http01MemoryHandler.js';
const memoryHandler = new Http01MemoryHandler();
app.use((req, res, next) => memoryHandler.handleRequest(req, res, next));
```
All handlers implement the `IChallengeHandler<T>` interface and can be combined in the `challengeHandlers` array.
## Creating Custom Handlers