Setu-TS
    Preparing search index...

    Interface ILifecycleApi

    Lifecycle hook registration surface. Hooks run in registration order within each phase.

    0.1.0

    interface ILifecycleApi {
        onBootstrap(fn: () => void | Promise<void>): void;
        onClose(fn: () => void | Promise<void>): void;
        onError(
            fn: (error: Error, ctx: IRequestContext) => void | Promise<void>,
        ): void;
        onInit(fn: () => void | Promise<void>): void;
        onRegister(fn: () => void | Promise<void>): void;
        onRequest(fn: (ctx: IRequestContext) => void | Promise<void>): void;
        onResponse(fn: (ctx: IRequestContext) => void | Promise<void>): void;
        onShutdown(fn: () => void | Promise<void>): void;
        onStopping(fn: () => void | Promise<void>): void;
    }
    Index
    • Runs immediately before the server starts listening.

      Parameters

      • fn: () => void | Promise<void>

        Hook body

      Returns void

    • Runs after shutdown completes.

      Parameters

      • fn: () => void | Promise<void>

        Hook body

      Returns void

    • Runs when an error escapes middleware or a handler.

      Parameters

      • fn: (error: Error, ctx: IRequestContext) => void | Promise<void>

        Hook body receiving the error and request context

      Returns void

    • Runs after all plugins have registered.

      Parameters

      • fn: () => void | Promise<void>

        Hook body

      Returns void

    • Runs during the owning plugin's registration.

      Parameters

      • fn: () => void | Promise<void>

        Hook body

      Returns void

    • Runs when shutdown begins — close connections, flush buffers here.

      By this point the application is already refusing new requests and the server socket is closed; use onStopping for work that must happen while traffic is still being served.

      Parameters

      • fn: () => void | Promise<void>

        Hook body

      Returns void

    • Runs at the very start of stop(), before the application begins refusing new requests.

      This is the only hook that runs while the application is still serving normally, which is what makes it the right home for "tell the outside world to stop sending me traffic" work — deregistering from a service registry, for instance. Deregistering in onShutdown instead means the socket is already closed by the time the registry hears about it, so callers keep being routed to a dead port for up to one health-check interval on every rolling deploy.

      Hooks run LIFO and are awaited, so a slow hook delays the whole shutdown and a rejecting one surfaces from stop() — but only after the shutdown has completed, because a hook failure must not be able to prevent the application stopping. With no hooks registered this window has zero width and stop() behaves exactly as it did before.

      Parameters

      • fn: () => void | Promise<void>

        Hook body

      Returns void

      0.2.0