Stone.js API
    Preparing search index...

    Node.js HTTP Adapter for the Stone.js framework.

    The NodeHTTPAdapter is responsible for integrating a Node.js HTTP/HTTPS server with the Stone.js framework, converting incoming HTTP requests into IncomingHttpEvent instances, and processing outgoing responses into the OutgoingHttpResponse format.

    It provides lifecycle hooks for initialization, termination, and error handling, ensuring seamless integration with Stone.js.

    The raw HTTP event type (e.g., IncomingMessage).

    The raw HTTP response type (e.g., ServerResponse).

    The server instance type (e.g., NodeHttpServer).

    The Stone.js incoming event type (e.g., IncomingHttpEvent).

    Options for creating an incoming event.

    The outgoing response type (e.g., OutgoingHttpResponse).

    The adapter context type (e.g., NodeHttpAdapterContext).

    Hierarchy

    • Adapter<
          IncomingMessage,
          ServerResponse,
          NodeHttpServer,
          IncomingHttpEvent,
          IncomingHttpEventOptions,
          OutgoingHttpResponse,
          NodeHttpAdapterContext,
      >
      • NodeHttpAdapter
    Index
    • Constructs a NodeHTTPAdapter 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 NodeHttpAdapter

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

      Parameters

      • context: NodeHttpAdapterContext

        The event context.

      • OptionaleventHandler: AdapterEventHandlerType<IncomingHttpEvent, OutgoingHttpResponse>

        The event handler to be run.

      Returns Promise<ServerResponse<IncomingMessage>>

      The raw response wrapper.

    • Protected

      Creates the HTTP or HTTPS server based on the adapter's configuration.

      Returns NodeHttpServer

      A NodeHttpServer instance.

    • Protected

      Handles incoming HTTP requests and sends them through the adapter's event pipeline.

      Parameters

      • rawEvent: IncomingMessage

        The raw HTTP request object.

      • rawResponse: ServerResponse

        The raw HTTP response object.

      Returns Promise<ServerResponse<IncomingMessage>>

      A promise resolving to a ServerResponse (e.g., 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

      • name: AdapterHookName

        The hook's name.

      • Optionalcontext: NodeHttpAdapterContext

        The event context.

      • Optionalerror: any

        The error to handle.

      Returns Promise<void>

    • Handle error.

      Parameters

      Returns Promise<AdapterEventBuilderType<ServerResponse<IncomingMessage>>>

      The raw response.

    • Handle the event.

      Parameters

      • context: NodeHttpAdapterContext

        The event context.

      • eventHandler: AdapterEventHandlerType<IncomingHttpEvent, OutgoingHttpResponse>

        The event handler to be run.

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

      The raw response wrapper.

    • Protected

      Applies denial-of-service hardening to the HTTP(S) server.

      Sets strict defaults for header count and connection timeouts (Slowloris, socket exhaustion, header floods). Every knob is overridable via stone.adapter.server (e.g. { headersTimeout: 30000, maxHeadersCount: 60 }); maxRequestsPerSocket is only applied when explicitly configured.

      Parameters

      Returns NodeHttpServer

      The hardened server.

    • Create pipeline options for the Adapter.

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

      The pipeline options for transforming the event.

    • Lifecycle hook for adapter initialization.

      This method is called during the adapter's startup process and performs tasks such as setting up exception listeners and verifying the runtime environment.

      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>,
          NodeHttpServer,
      >

      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.

    • Starts the HTTP/HTTPS server and listens for incoming requests.

      Type Parameters

      Returns Promise<ExecutionResultType>

      A promise that resolves to an ExecutionResultType (usually NodeHttpServer) when the server starts successfully.

      If the server encounters an error during initialization.

      const adapter = NodeHTTPAdapter.create(options);
      await adapter.run();
      console.log('Server is running');
    • Send the raw event through the destination.

      Parameters

      • context: NodeHttpAdapterContext

        The event context.

      • eventHandler: AdapterEventHandlerType<IncomingHttpEvent, OutgoingHttpResponse>

        The event handler to be run.

      Returns Promise<ServerResponse<IncomingMessage>>

      Platform-specific response.

      IntegrationError

    • Protected

      Sets up global error handlers for uncaught exceptions and unhandled rejections. Ensures critical errors are logged and the process exits safely.

      Returns void

    • Sets up a shutdown listener to gracefully stop the server on SIGINT/SIGTERM.

      Graceful means "let the requests in flight finish", not "wait for every socket ever opened". close() alone means the latter: a keep-alive connection sitting idle has no request to finish, yet it holds the callback, so process.exit(0) never runs. A signalled process then never dies. Whatever sent the signal waits for its own timeout and hard-kills, which is how a rolling deploy turns a graceful shutdown into a killed one and an onStop hook becomes a lie.

      So idle connections are closed immediately, requests in flight get the grace period, and the process exits either way.

      Returns void

    • Validate the context and event handler.

      Parameters

      • context: NodeHttpAdapterContext

        The context to validate.

      • eventHandler: AdapterEventHandlerType<IncomingHttpEvent, OutgoingHttpResponse>

        The event handler to validate.

      Returns void

      IntegrationError

    • Creates a new NodeHTTPAdapter instance.

      Parameters

      • blueprint: IBlueprint

        The application blueprint.

      Returns NodeHttpAdapter

      A new instance of NodeHTTPAdapter.

      const adapter = NodeHTTPAdapter.create(blueprint);
      await adapter.run();