Skip to content
Français

serveTriggers

import { serveTriggers } from "@elie-laloum/outpost";

Start an HTTP server that verifies each POST with its route source and publishes the job selected by on() as trigger:<path>:<delivery>; redeliveries publish nothing new. It answers 202, 204, 400, 401, 404, 405, 413, 500 or 503, a source can replace 202 and 204, and it resolves once listening; invalid options or an unavailable port reject. The caller closes the server, then its queue.

Complete example and detailed rules.

  • optionsRequired
    TriggerServerOptions
    Queue, routes, listening address, body limit and failure observer.
  • options.queueRequired
    TaskQueue
    Queue receiving the jobs; a rejected enqueue answers 503.
  • options.routesRequired
    readonly TriggerRoute[]
    At least one route with a unique path.
  • options.hostOptional
    string | undefined
    Listening address; defaults to 127.0.0.1. Expose the server through a TLS-terminating proxy.
  • options.portOptional
    number | undefined
    Listening port; 0 or omitted selects a free port reported in url.
  • options.maxBytesOptional
    number | undefined
    Request body limit in bytes; defaults to 1 MiB, at most 25 MiB. Larger bodies answer 413.
  • options.onErrorOptional
    ((error: unknown, failure: TriggerFailure) => void) | undefined
    Observes verification, routing and publication failures with the path and, after verification, the delivery; never receives secrets. Errors thrown by the callback are ignored.

Promise<TriggerServer>

export declare function serveTriggers(
  options: TriggerServerOptions,
): Promise<TriggerServer>;