Class GatewayController

A utility controller that generates routes that act as a gateway for a specific API.

Prettierignore

Constructors

Properties

_apiConfigEndpoints: EndpointsDict

The generated endpoints for the API client configuration the controller can generate.

_apiConfigUrl: string

The entry URL for the API client configuration the controller can generate.

_endpoints: Record<string, GatewayConfigEndpointDefinition>

A flat dictionary with the endpoints information.

_gatewayConfig: GatewayConfig

The information, url and endpoints, for the gateway the controller will make requests to.

_getHelperService: (() => undefined | Partial<{
    handleEndpointError: GatewayHelperServiceErrorHandler;
    handleEndpointResponse: GatewayHelperServiceResponseHandler;
    reduceEndpointRequest: GatewayHelperServiceRequestReducer;
    reduceEndpointResponse: GatewayHelperServiceResponseReducer;
    shouldStreamEndpointResponse: GatewayHelperServiceStreamVerification;
}>)

A function to get a possible helper service. This is injected as a "getter" to not interrupt the DIC "lifecycle": controllers are initialized right when the app starts, and injecting a reference would force the service to be initialized too, even if a request is not being made.

Type declaration

The controller customization options.

_route: string

The route in which the controller is mounted.

_routeExpression: RegExp

A regular expression that will be used to remove the controller route from a request path. This will allow the main middleware to extract the path to where the request should be made.

The list of routes the controller can handle.

http: HTTP

The service that makes HTTP requests.

Accessors

Methods

  • This is a "proxy method" to call the helper service's function that handles an error on an endpoint request.

    The reason this is a "proxy method" is in case the controller gets subclassed and "used itself as a helper" instead of relying on a difference one.

    If the helper doesn't implement handleEndpointError, it will just send the error to the next middleware/error handler.

    Parameters

    Returns void

  • This is a "proxy method" to call the helper service's function that handles a response in case it already said that a response shouldn't be streamed.

    The reason this is a "proxy method" is in case the controller gets subclassed and "used itself as a helper" instead of relying on a difference one.

    If the helper doesn't implement shouldStreamEndpointResponse, it will throw an error.

    Parameters

    Returns Promise<void>

    Throws

    If the helper doesn't implement handleEndpointResponse.

  • This is a "proxy method" to call the helper service's function that can modify an endpoint response before it gets processed.

    The reason this is a "proxy method" is in case the controller gets subclassed and "used itself as a helper" instead of relying on a difference one.

    If the helper doesn't implement reduceEndpointResponse, it will just return information for the response.

    Parameters

    Returns Promise<Response>

  • This is a "proxy method" to call the helper service's function that can decide if an endpoint response should be streamed or not.

    The reason this is a "proxy method" is in case the controller gets subclassed and "used itself as a helper" instead of relying on a difference one.

    If the helper doesn't implement shouldStreamEndpointResponse, it will just return true.

    Parameters

    Returns Promise<boolean>

  • Mounts the middlewares in the router in order to make the requests.

    Parameters

    • router: Router

      A reference to the application router.

    • middlewares: ExpressMiddleware[] = []

      A list of extra middlewares to execute before the gateway middleware.

    Returns Router

Generated using TypeDoc