RouterStack

Provides Stack item handler and methods.

Constructor

new RouterStack()

Create new stack instance.

Methods

add(func)

Add new function to stack items.

Stack function types

  • middleware
  • route:<method>
  • resource:<method>
  • fallback
Parameters:
NameTypeDescription
funcfunction

Route/middleware function.

Example
const func1 = function(req, res, next) {
  if (req.method() === 'POST') {
    res.status(405).send();
  } else {
    next();
  }
};

setFuncName(func1, 'middleware');
stack.add(func1);

  ..

const func2 = function(req, res) {
  res.setHeader('Content-Type', 'text/html');
  res.status(200).send('Hello World');
};

setFuncName(func2, 'route:get');
stack.add(func2);

exec(req, res) → {Promise|undefined}

Execute stored functions (a)synchronously.

Order by priority.

Middleware, Routes, Resources, fallback

Parameters:
NameTypeDescription
reqRouterRequest

Request instance.

resRouterResponse

Response instance.

Returns:
Type: 
Promise | undefined
Example
stack.exec(req, res);

// updated instance
res.data();

  ..

stack.exec(req, res)
  .then(() => res.data())