Documentation
    Preparing search index...

    The Server class provides the core HTTP server implementation for AdonisJS.

    It handles incoming HTTP requests by processing them through middleware pipelines, routing them to appropriate handlers, and managing response generation. The server supports custom error handling, middleware registration, and various Node.js HTTP server configurations.

    const server = new Server(app, encryption, emitter, logger, config)
    server.use([AuthMiddleware, CorsMiddleware])
    server.errorHandler(() => import('./error_handler.ts'))
    await server.boot()

    http.createServer(server.handle.bind(server))
    Index

    Constructors

    • Creates a new Server instance

      Parameters

      • app: Application<any>

        AdonisJS application instance

      • encryption: Encryption

        Encryption service for secure operations

      • emitter: EmitterLike<HttpServerEvents>

        Event emitter for server lifecycle events

      • logger: Logger

        Logger instance for server operations

      • config: ServerConfig

        Server configuration settings

      Returns Server

    Accessors

    • get booted(): boolean

      Indicates whether the server has completed its boot process

      Returns boolean

    • get usingAsyncLocalStorage(): boolean

      Indicates whether async local storage is enabled for request context

      Returns boolean

    Methods

    • Registers global middleware to run on all incoming HTTP requests

      Parameters

      • middleware: LazyImport<MiddlewareAsClass>[]

        Array of lazy-imported middleware classes

      Returns this

      The Server instance for method chaining

    • Initializes the server by compiling middleware, committing routes, and resolving handlers

      Performs the following operations:

      • Compiles the middleware stack
      • Commits registered routes to the router
      • Resolves and instantiates the custom error handler

      Returns Promise<void>

    • Configures the underlying Node.js HTTP/HTTPS server with timeout settings

      Parameters

      • server:
            | Server<typeof IncomingMessage, typeof ServerResponse>
            | Server<typeof IncomingMessage, typeof ServerResponse>

        Node.js HTTP or HTTPS server instance

      Returns void

    • Gets the underlying Node.js HTTP/HTTPS server instance

      Returns
          | undefined
          | Server<typeof IncomingMessage, typeof ServerResponse>
          | Server<typeof IncomingMessage, typeof ServerResponse>

      The configured server instance or undefined if not set

    • Creates a Request instance from Node.js request/response objects

      Parameters

      • req: IncomingMessage

        Node.js IncomingMessage

      • res: ServerResponse

        Node.js ServerResponse

      Returns Request

      New Request instance

    • Creates a Response instance from Node.js request/response objects

      Parameters

      • req: IncomingMessage

        Node.js IncomingMessage

      • res: ServerResponse

        Node.js ServerResponse

      Returns Response

      New Response instance

    • Creates an HttpContext instance with request-specific logger

      Parameters

      • request: Request

        Request instance

      • response: Response

        Response instance

      • resolver: ContainerResolver<any>

        Container resolver for dependency injection

      Returns HttpContext

      New HttpContext instance

    • Handles an incoming HTTP request by creating context and processing through pipeline

      Parameters

      • req: IncomingMessage

        Node.js IncomingMessage

      • res: ServerResponse

        Node.js ServerResponse

      Returns Promise<any>

      Promise that resolves when request processing is complete