smartacme/readme.plan.md

2.2 KiB

Plan: Diskless HTTP-01 Handler and Renaming Existing Handler

This plan outlines steps to rename the existing filesystem-based HTTP-01 handler to Http01Webroot and introduce a new diskless (in-memory) HTTP-01 handler for integration with arbitrary HTTP servers (e.g., Express).

1. Rename existing handler to Http01Webroot

  • In ts/handlers/Http01Handler.ts:
    • Rename Http01HandlerOptions to Http01WebrootOptions.
    • Rename class Http01Handler to Http01Webroot.
    • Remove the legacy alias; rename the handler directly.
    • In ts/handlers/index.ts:
      • Export Http01Webroot under its new name.
      • Remove any Http01Handler export.
      • Update existing tests (e.g., test.handlers-http01.ts) to import Http01Webroot instead of Http01Handler.

2. Add new diskless (in-memory) HTTP-01 handler

  • Create ts/handlers/Http01MemoryHandler.ts:
    • Implement IChallengeHandler<{ token: string; keyAuthorization: string; webPath: string }>, storing challenges in a private Map<string, string>.
    • prepare(): add token→keyAuthorization mapping.
    • verify(): no-op.
    • cleanup(): remove mapping.
    • Add handleRequest(req, res, next?) method:
      • Parse /.well-known/acme-challenge/:token from req.url.
      • If token exists, respond with the key authorization and status 200.
      • If missing and next provided, call next(), otherwise respond 404.
  • Export Http01MemoryHandler in ts/handlers/index.ts.

3. Write tests for Http01MemoryHandler

  • Create test/test.handlers-http01-memory.ts:
    • Use tap and expect to:
      1. prepare() a challenge.
      2. Invoke handleRequest() with a fake req/res to confirm 200 and correct body.
      3. cleanup() the challenge.
      4. Confirm handleRequest() now yields 404.

4. Update documentation

  • Add examples in readme.md showing how to use both Http01Webroot and the new Http01MemoryHandler:
    • Sample code for Express integration using handleRequest.

5. Build and test

  • Run pnpm build and pnpm test, ensuring existing tests are updated for Http01Webroot and new tests pass.

Please review and let me know if this plan makes sense before proceeding with implementation.