Options
All
  • Public
  • Public/Protected
  • All
Menu

A router.

Hierarchy

  • Router

Index

Constructors

constructor

  • Parameters

    • Default value options: RouterOptions = { excludeBuiltInRoutes: false }

    Returns Router

Properties

routeGroups

routeGroups: RouteGroupList = new RouteGroupList()

Methods

delete

  • Adds a route matching DELETE HTTP method.

    Parameters

    • criteria: RouteCriteria | string

      Either the path as a string or an object with path, headers and cookies.

    • handler: RouteHandler

      A handler function that will be called when the route is matched

    Returns this

    A self-reference, suitable for chaining.

destination

  • destination(name: string, router: Router): this
  • Adds a named destination to which you can map traffic using the traffic shaping settings in your environment in the XDN developer console

    Parameters

    • name: string

      The name of the destination

    • router: Router

      A router to use when handling requests

    Returns this

    A self-reference, suitable for chaining.

fallback

  • Adds a route that matches all requests

    Parameters

    • handler: RouteHandler

      A handler function that will be called when the route is matched

    Returns this

    A self-reference, suitable for chaining.

get

  • Adds a route matching GET HTTP method.

    Parameters

    • criteria: RouteCriteria | string

      Either the path as a string or an object with path, headers and cookies.

    • handler: RouteHandler

      A handler function that will be called when the route is matched

    Returns this

    A self-reference, suitable for chaining.

getPlugins

  • getPlugins(): PluginBase[]
  • Returns all plugins, including those registered on destination routers.

    Returns PluginBase[]

head

  • Adds a route matching HEAD HTTP method.

    Parameters

    • criteria: RouteCriteria | string

      Either the path as a string or an object with path, headers and cookies.

    • handler: RouteHandler

      A handler function that will be called when the route is matched

    Returns this

    A self-reference, suitable for chaining.

isRequestFromEdge

  • isRequestFromEdge(req: Request): boolean
  • Returns true if the request came through XDN edge.

    Notes:

    • If the request came through XDN edge then x-xdn-version has been injected.

    Parameters

    Returns boolean

match

  • Adds a route matching all methods.

    Example:

     new Router().match('/p/:productId', ({ cache, proxy }) => {
       cache({
         edge: {
           maxAgeSeconds: 60 * 60 * 24
         }
       })
    
       proxy('origin')
     })

    Parameters

    • criteria: RouteCriteria | string

      Either the path as a string or an object with path, method, and headers.

    • handler: RouteHandler

      A handler function that will be called when the route is matched

    Returns this

    A self-reference, suitable for chaining.

options

  • Adds a route matching OPTIONS HTTP method.

    Parameters

    • criteria: RouteCriteria | string

      Either the path as a string or an object with path, headers and cookies.

    • handler: RouteHandler

      A handler function that will be called when the route is matched

    Returns this

    A self-reference, suitable for chaining.

patch

  • Adds a route matching PATCH HTTP method.

    Parameters

    • criteria: RouteCriteria | string

      Either the path as a string or an object with path, headers and cookies.

    • handler: RouteHandler

      A handler function that will be called when the route is matched

    Returns this

    A self-reference, suitable for chaining.

post

  • Adds a route matching POST HTTP method.

    Parameters

    • criteria: RouteCriteria | string

      Either the path as a string or an object with path, headers and cookies.

    • handler: RouteHandler

      A handler function that will be called when the route is matched

    Returns this

    A self-reference, suitable for chaining.

put

  • Adds a route matching PUT HTTP method.

    Parameters

    • criteria: RouteCriteria | string

      Either the path as a string or an object with path, headers and cookies.

    • handler: RouteHandler

      A handler function that will be called when the route is matched

    Returns this

    A self-reference, suitable for chaining.

run

  • Handles a request, sending the response by running the handler for each matched route.

    Parameters

    Returns Promise<void>

use

  • use(pluginInstance: PluginBase): this
  • Constructs plugin and pushes it to registered plugins

    Parameters

    • pluginInstance: PluginBase

      A plugin to use.

    Returns this

    A self-reference, suitable for chaining.

Generated using TypeDoc