Type alias ServerOpts<Meta>

ServerOpts<Meta>: { authenticate?: ((authentication: Authentication, apiContext: ApiContext) => boolean | Promise<boolean>); defaultAuthentication?: Authentication; mapError?: ((error: unknown) => ApiError | undefined); maxBodyBytes?: number; middlewares?: Middleware<Meta>[]; port?: number; restMiddleware?: RestMiddleware[]; server?: Server; staticFiles?: StaticFileOpts }

Options passed to createApiServer for running your server

Params

Meta The custom Metadata type

Type Parameters

Type declaration

  • Optional authenticate?: ((authentication: Authentication, apiContext: ApiContext) => boolean | Promise<boolean>)
      • (authentication: Authentication, apiContext: ApiContext): boolean | Promise<boolean>
      • Method to take in authentication data and return whether the user is allowed. It may be async, and is passed the endpoint's context, so it can add to it (who's calling, say). The authentication is read and put on the context whether or not this is defined.

        Parameters

        Returns boolean | Promise<boolean>

  • Optional defaultAuthentication?: Authentication

    Default Authentication metadata (as in, if {type: "bearer", token: ""} is provided, estuary-rpc-server will attempt to extract a bearer token from all requests, and only allow requests to complete if that token results in the authenticate method passes, or unless the metadata specifically assigns authentication for a given endpoint to null)

  • Optional mapError?: ((error: unknown) => ApiError | undefined)
      • (error: unknown): ApiError | undefined
      • Maps errors that endpoints throw (your own error classes, say) to ApiErrors, to answer with their status

        Parameters

        • error: unknown

        Returns ApiError | undefined

  • Optional maxBodyBytes?: number

    Largest request body read, in bytes; a larger one is refused with 413

    Default Value

    10 MiB

  • Optional middlewares?: Middleware<Meta>[]

    Midlewares to execute while executing all endpoints, using a complet ApiContext and Metadata definition

  • Optional port?: number

    Port number for createApiServer to listen on; without one, it doesn't listen (the caller does)

  • Optional restMiddleware?: RestMiddleware[]

    Middlewares to execute before executing REST endpoints, using only data available in the IncomingMessage

  • Optional server?: Server

    An existing server (an https one, say) to serve the API on, rather than a new http one

  • Optional staticFiles?: StaticFileOpts

    See StaticFileOpts for usage around serving staticfiles in common patterns

Generated using TypeDoc