Methods
add(func)
Add new function to stack items.
Stack function types
- middleware
- route:<method>
- resource:<method>
- fallback
Parameters:
Name | Type | Description |
---|---|---|
func | function | Route/middleware function. |
- Source
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:
Name | Type | Description |
---|---|---|
req | RouterRequest | Request instance. |
res | RouterResponse | Response instance. |
- Source
Returns:
- Type:
- Promise |
undefined
Example
stack.exec(req, res);
// updated instance
res.data();
..
stack.exec(req, res)
.then(() => res.data())