Fake Mirrors
    Preparing search index...

    Class HttpServerRouter

    Represents the http-server router.

    Depends:

    import { DIContainer } from '@famir/common'
    import { HTTP_SERVER_ROUTER, HttpServerRouter } from '@famir/http-server'

    // Get container singleton
    const container = DIContainer.getInstance()

    // Register in DI container
    HttpServerRouter.register(container)

    // Resolve from DI container
    const router = container.resolve<HttpServerRouter>(HTTP_SERVER_ROUTER)

    // Add custom middleware
    router.addMiddleware('test', async (ctx, next) => {
    // Send simple response
    ctx.status(200)
    ctx.responseBody.setText('Hello')

    await ctx.sendResponse()

    // Goto next middleware
    await next()
    })

    // Activate router
    router.activate()
    • Adds a middleware in the chain.

      Middleware can only be added before the router is activated.

      Parameters

      • name: string

        The unique name for the middleware.

      • handler: HttpServerMiddleware

        The middleware handler function.

      Returns void

      Error If the router is already active.

      Error If a middleware with the same name already exists.

    • Retrieves a middleware by its index.

      Middleware can only be retrieved after the router is activated.

      Parameters

      • idx: number

        The index position of the middleware.

      Returns [string, HttpServerMiddleware] | undefined

      The middleware tuple with name and handler, or undefined if not found.

      Error If the router is not active.