Stone.js API
    Preparing search index...

    GCP Cloud Functions HTTP Adapter for the Stone.js framework.

    The GcpCloudFunctionsHttpAdapter integrates a Google Cloud Functions HTTP function (the Functions Framework (req, res) signature) with the Stone.js framework. It converts the incoming Express-flavoured request into an IncomingHttpEvent, runs it through the kernel, and writes the OutgoingHttpResponse back onto the response object.

    Unlike the Node HTTP adapter, it does NOT create or own an HTTP server: the platform owns the process lifecycle and the socket. run() returns the handler that the Functions Framework invokes per request.

    Cloud Run runs a container with a normal long-running HTTP server, so it does not need this adapter, use @stone-js/node-http-adapter as-is. This adapter is specifically for the event-driven HTTP functions runtime (1st and 2nd gen Cloud Functions).

    Hierarchy

    • Adapter<
          IncomingMessage,
          ServerResponse,
          undefined,
          IncomingHttpEvent,
          IncomingHttpEventOptions,
          OutgoingHttpResponse,
          GcpCloudFunctionsHttpAdapterContext,
      >
      • GcpCloudFunctionsHttpAdapter
    Index
    • Constructs a GcpCloudFunctionsHttpAdapter instance.

      This constructor is protected and is intended to be used via the static create method.

      Parameters

      • blueprint: IBlueprint

        The application blueprint for dependency resolution.

      Returns GcpCloudFunctionsHttpAdapter

    blueprint: IBlueprint
    hooks: AdapterHookType<
        GcpCloudFunctionsHttpAdapterContext,
        ServerResponse<IncomingMessage>,
    >
    logger: ILogger
    middleware: AdapterMixedPipeType<
        GcpCloudFunctionsHttpAdapterContext,
        ServerResponse<IncomingMessage>,
    >[]
    resolvedErrorHandlers: Record<
        string,
        IAdapterErrorHandler<RawEventType, RawResponseType, ExecutionContextType>,
    >
    • Build the raw response.

      Parameters

      • context: GcpCloudFunctionsHttpAdapterContext

        The event context.

      • OptionaleventHandler: AdapterEventHandlerType<IncomingHttpEvent, OutgoingHttpResponse>

        The event handler to be run.

      Returns Promise<ServerResponse<IncomingMessage>>

      The raw response wrapper.

    • Protected

      Handles an incoming HTTP request and sends it through the adapter's event pipeline.

      Parameters

      Returns Promise<ServerResponse<IncomingMessage>>

      A promise resolving to the ServerResponse.

    • Execute the event handler lifecycle hooks.

      Parameters

      • hook: KernelHookName

        The hook to execute.

      • eventHandler: AdapterEventHandlerType<IncomingHttpEvent, OutgoingHttpResponse>

        The event handler to be run.

      Returns Promise<void>

    • Execute adapter lifecycle hooks.

      Parameters

      Returns Promise<void>

    • Handle error.

      Parameters

      Returns Promise<AdapterEventBuilderType<ServerResponse<IncomingMessage>>>

      The raw response.

    • Handle the event.

      Parameters

      Returns Promise<
          IAdapterEventBuilder<
              RawResponseOptions,
              IRawResponseWrapper<ServerResponse<IncomingMessage>>,
          >,
      >

      The raw response wrapper.

    • Create pipeline options for the Adapter.

      Returns PipelineOptions<
          GcpCloudFunctionsHttpAdapterContext,
          AdapterEventBuilderType<ServerResponse<IncomingMessage>>,
      >

      The pipeline options for transforming the event.

    • Lifecycle hook for adapter initialization.

      The platform owns the process, so this only guards the runtime environment and fires the onStart hooks; it does NOT bind process signals or a server (the runtime manages shutdown).

      Returns Promise<void>

      If the adapter is used outside a Node.js context.

    • Get the error handler for the given error.

      Parameters

      • error: Error

        The error to get the handler for.

      Returns IAdapterErrorHandler<
          IncomingMessage,
          ServerResponse<IncomingMessage>,
          undefined,
      >

      The error handler.

      IntegrationError

    • Get the event handler for the adapter.

      Returns AdapterEventHandlerType<IncomingHttpEvent, OutgoingHttpResponse>

      The event handler for the adapter.

      If the event handler is missing.

    • Boots the application and returns the HTTP function handler.

      Register the returned handler with the Functions Framework:

      import * as functions from '@google-cloud/functions-framework'
      functions.http('stone', await StoneFactory.create({ ...blueprint }).run())

      Type Parameters

      Returns Promise<ExecutionResultType>

      A promise resolving to the (req, res) handler invoked per request.

      If the adapter is used outside a Node.js context.

    • Send the raw event through the destination.

      Parameters

      Returns Promise<ServerResponse<IncomingMessage>>

      Platform-specific response.

      IntegrationError

    • Validate the context and event handler.

      Parameters

      • context: GcpCloudFunctionsHttpAdapterContext

        The context to validate.

      • eventHandler: AdapterEventHandlerType<IncomingHttpEvent, OutgoingHttpResponse>

        The event handler to validate.

      Returns void

      IntegrationError

    • Creates a new GcpCloudFunctionsHttpAdapter instance.

      Parameters

      • blueprint: IBlueprint

        The application blueprint.

      Returns GcpCloudFunctionsHttpAdapter

      A new instance of GcpCloudFunctionsHttpAdapter.

      const adapter = GcpCloudFunctionsHttpAdapter.create(blueprint);
      const handler = await adapter.run();