Class Router

Constructors

Methods

  • Registers a route for HTTP DELETE requests.

    Parameters

    • path: string | RegExp

      The URL path or pattern for the route.

    • cb: Handler[]

      An array of middleware or handler functions to execute for this route.

    Returns this

    The current instance for method chaining.

  • Registers a route for HTTP GET requests.

    Parameters

    • path: string | RegExp

      The URL path or pattern for the route.

    • cb: Handler[]

      An array of middleware or handler functions to execute for this route.

    Returns this

    The current instance for method chaining.

  • Finds and returns the route matching the given path and method.

    Parameters

    • path: string

      The requested path.

    • method: string

      The HTTP method (e.g., "GET").

    Returns any

    The matching route or undefined.

  • Registers a new route group with common base path and middleware.

    Parameters

    • basePath: string | RegExp

      The base path or RegExp.

    • callback: (methods: any) => void

      Callback to define routes within the group.

    Returns this

    The Router instance for chaining.

  • Registers a route for HTTP HEAD requests.

    Parameters

    • path: string | RegExp

      The URL path or pattern for the route.

    • cb: Handler[]

      An array of middleware or handler functions to execute for this route.

    Returns this

    The current instance for method chaining.

  • Dynamically imports routes from a directory and registers them.

    Parameters

    • p: string

      Path to the directory containing route files.

    • tpl: false | Tpl = false

      Optional template instance to use with the routes.

    Returns Promise<Router>

    The Router instance for chaining.

  • Registers a route for HTTP PATCH requests.

    Parameters

    • path: string | RegExp

      The URL path or pattern for the route.

    • cb: Handler[]

      An array of middleware or handler functions to execute for this route.

    Returns this

    The current instance for method chaining.

  • Registers a route for HTTP POST requests.

    Parameters

    • path: string | RegExp

      The URL path or pattern for the route.

    • cb: Handler[]

      An array of middleware or handler functions to execute for this route.

    Returns this

    The current instance for method chaining.

  • Registers a route for HTTP PUT requests.

    Parameters

    • path: string | RegExp

      The URL path or pattern for the route.

    • cb: Handler[]

      An array of middleware or handler functions to execute for this route.

    Returns this

    The current instance for method chaining.

  • Serves static files from a specified directory.

    Parameters

    • options: { dir?: string; route?: RegExp }

      Options for serving static files.

      • Optionaldir?: string

        Directory containing the static files.

      • Optionalroute?: RegExp

        Regular expression to match the route for static files.

    Returns this

    The Router instance for chaining.

  • Merges routes or assigns a template instance to the Router.

    Parameters

    • obj: Tpl | Router

      An instance of Router or Tpl.

    Returns void