@accelerated-software-development/caddy-api-client - v0.2.2
    Preparing search index...

    Class CaddyClient

    Client for interacting with Caddy Admin API

    Index

    Constructors

    Methods

    • Adapt a configuration from one format to another Commonly used to convert Caddyfile to JSON configuration.

      Parameters

      • config: string

        The configuration content to adapt

      • adapter: string = "caddyfile"

        The adapter to use (e.g., "caddyfile")

      Returns Promise<unknown>

      The adapted configuration as JSON

    • Add a route to a server

      Parameters

      • server: string

        Server name

      • route: CaddyRoute

        Route configuration

      Returns Promise<boolean>

      True if route was added, false if already exists

    • Add multiple routes to a server (convenience method to avoid loops) This method adds routes one at a time and handles idempotency for each.

      Parameters

      • server: string

        Server name

      • routes: CaddyRoute[]

        Array of routes to add

      Returns Promise<{ added: number; skipped: number }>

      Object with counts of added and skipped routes

      const routes = buildServiceRoutes({ host: "api.localhost", dial: "localhost:3000" });
      const result = await client.addRoutes("https_server", routes);
      console.log(`Added ${result.added}, skipped ${result.skipped}`);
    • Get current Caddy configuration

      Returns Promise<unknown>

      Full Caddy configuration as JSON

    • Get routes for a specific server

      Parameters

      • server: string

        Server name (e.g., "https_server")

      Returns Promise<CaddyRoute[]>

      Array of routes

    • Get configuration for a specific server

      Parameters

      • server: string

        Server name

      Returns Promise<Record<string, unknown>>

      Server configuration object

    • Get information about all servers

      Returns Promise<unknown>

      Server configurations

    • Get Caddy version information

      Returns Promise<unknown>

      Version information

    • Insert a route at a specific position in the server's route list

      Parameters

      • server: string

        Server name

      • route: CaddyRoute

        Route to insert

      • position: "beginning" | "end" | "after-health-checks" = "after-health-checks"

        Where to insert the route

      Returns Promise<void>

      void

    • Replace all routes for a server (PATCH)

      Parameters

      • server: string

        Server name

      • routes: CaddyRoute[]

        Array of routes

      Returns Promise<void>

    • Patch server configuration

      Parameters

      • serverConfig: Record<string, unknown>

        Server configuration object

      Returns Promise<void>

    • Remove a route by its

      Parameters

      • server: string

        Server name

      • id: string

        Route

      Returns Promise<boolean>

      true if route was found and removed, false otherwise

      to remove

    • Remove routes matching a hostname

      Parameters

      • hostname: string

        Hostname to match

      • server: string = "https_server"

        Server name

      Returns Promise<number>

      Number of routes removed

    • Replace a route by its

      Parameters

      • server: string

        Server name

      • id: string

        Route

      • newRoute: CaddyRoute

        New route configuration

      Returns Promise<boolean>

      true if route was found and replaced, false otherwise

      to replace

    • Make an HTTP request to Caddy Admin API with timeout

      Parameters

      • path: string

        API endpoint path

      • options: RequestInit = {}

        Fetch options

      Returns Promise<Response>

      Response object

      NetworkError, TimeoutError, CaddyApiError

    • Gracefully stop the Caddy server This triggers a graceful shutdown, allowing active connections to complete.

      Returns Promise<void>

      CaddyApiError if the stop request fails