Skip to content

ui-router-server / connect / createConnectMiddleware

Function: createConnectMiddleware() ​

ts
function createConnectMiddleware(router, options?): ConnectMiddleware;

Defined in: connect.ts:232

Wraps a ServerRouter as Connect middleware. Mount it BEFORE the static layer; the default host serves shells by rewriting req.url and next()ing into it. resolve() is always async (the simulate tier's lazy boundary), which Connect absorbs naturally — with matcher-tier mounts nothing async ever actually runs.

Under a base, the mounts see each url with the base taken off, and every url the middleware writes gets it back.

  • redirect → writeHead(302, { Location }), the request's search MERGED into the verdict's location via mergeSearch (targets that declare their own query keep it — never ?a=1?b=2).
  • shell → Link: <mount>; rel="canonical" (the shell is the same representation at every route path), then serveShell.
  • shell with status (the otherwise projection) → validators stripped, downstream status relabeled, no canonical Link (a 404 is not an alternate representation of the mount root), then serveShell.
  • notFound with a mount → serveNotFound (honest 404).
  • notFound without a mount, or a non-navigation request → next().
  • delegate → next() with `delegates: 'next'`; mount the handlers for delegating states downstream.
  • response → next() with `responses: 'next'`; answer response states downstream.

Parameters ​

ParameterType
routerServerRouter
options?ConnectAdapterOptions

Returns ​

ConnectMiddleware

Throws ​

at construction when the router names delegate keys and delegates is not 'next', or declares response states and responses is not 'next'