Beignet API reference
    Preparing search index...

    Interface NextServer<Ctx, Ports, ServiceInput>

    Beignet server adapted for Next.js route handlers and server components.

    interface NextServer<
        Ctx,
        Ports extends AnyPorts = AnyPorts,
        ServiceInput = void,
    > {
        api: (req: Request) => Promise<Response>;
        contracts: readonly ContractLike[];
        createContextFromNext: () => Promise<Ctx>;
        createRequestContext: (req: HttpRequestLike) => Promise<Ctx>;
        createServiceContext: (
            ...args: ServiceContextInputArgs<ServiceInput>,
        ) => Promise<Ctx>;
        ports: Ports;
        rawRoute: (
            init: RawRouteInit,
        ) => {
            handle: (
                fn: Handler<Ctx, HttpContractConfig>,
            ) => (req: Request) => Promise<Response>;
        };
        route: <CLike extends ContractLike>(
            contractLike: CLike,
        ) => {
            handle: (
                fn: Handler<Ctx, ResolveContract<CLike>>,
            ) => (req: Request) => Promise<Response>;
        };
        runServiceContext: <T>(
            ...args: [
                ...ServiceContextInputArgs<ServiceInput>[],
                fn: (ctx: Ctx) => T | Promise<T>,
            ],
        ) => Promise<T>;
        stop: () => Promise<void>;
    }

    Type Parameters

    Index
    api: (req: Request) => Promise<Response>

    Catch-all Next.js route handler.

    contracts: readonly ContractLike[]

    Registered contract inputs.

    createContextFromNext: () => Promise<Ctx>

    Create app context from next/headers for Server Components.

    createRequestContext: (req: HttpRequestLike) => Promise<Ctx>

    Build a fully assembled request context from a framework-neutral request.

    createServiceContext: (
        ...args: ServiceContextInputArgs<ServiceInput>,
    ) => Promise<Ctx>

    Build a fully assembled service context for schedules, outbox drains, commands, and background work.

    Requires context.service to be declared in createNextServer(...).

    ports: Ports

    Final app ports after provider setup.

    rawRoute: (
        init: RawRouteInit,
    ) => {
        handle: (
            fn: Handler<Ctx, HttpContractConfig>,
        ) => (req: Request) => Promise<Response>;
    }

    Build a Next.js route handler for a route that cannot be a contract — webhooks, third-party auth callbacks, streaming endpoints — that still runs the whole server pipeline: hooks (rate limiting, idempotency, CORS, logging, error reporting), context creation, instrumentation, and framework error mapping.

    Request parsing and validation are skipped and the request body is left unconsumed, so the handler owns body reading — for example webhook signature verification over the exact raw bytes. Metadata-driven hooks read init.metadata. Raw routes are not added to the route registry; export the returned handler from the route file that owns the path.

    route: <CLike extends ContractLike>(
        contractLike: CLike,
    ) => {
        handle: (
            fn: Handler<Ctx, ResolveContract<CLike>>,
        ) => (req: Request) => Promise<Response>;
    }

    Register and build a single Next.js route handler imperatively.

    runServiceContext: <T>(
        ...args: [
            ...ServiceContextInputArgs<ServiceInput>[],
            fn: (ctx: Ctx) => T | Promise<T>,
        ],
    ) => Promise<T>

    Build a service context and run fn inside a scoped ambient correlation frame, returning its result.

    This is the script-safe counterpart to createServiceContext(...). Requires context.service to be declared in createNextServer(...).

    stop: () => Promise<void>

    Stop installed providers.