mirror of https://gitee.com/bigwinds/arangodb
Extract dispatch from router
This commit is contained in:
parent
95dea0cd14
commit
2633b0109b
|
@ -140,20 +140,6 @@ module.exports = class Router extends SwaggerContext {
|
|||
const root = new Map();
|
||||
this._tree = root;
|
||||
|
||||
// middleware always implicitly ends in a wildcard
|
||||
// child routers always explicitly end in wildcards
|
||||
// routes may explicitly end in a wildcard
|
||||
// static names have precedence over params
|
||||
// params have precedence over wildcards
|
||||
// middleware is executed in order of precedence
|
||||
// implicit 404 in middleware does not fail the routing
|
||||
// router.all ONLY affects routes of THAT router (and its children)
|
||||
// * router.all does NOT affect routes of sibling routers *
|
||||
|
||||
// should child routers have precedence over routes?
|
||||
// ideally they should respect each others precedence
|
||||
// and be treated equally
|
||||
|
||||
for (let middleware of this._middleware) {
|
||||
let node = root;
|
||||
for (let token of middleware._pathTokens) {
|
||||
|
@ -186,13 +172,6 @@ module.exports = class Router extends SwaggerContext {
|
|||
}
|
||||
}
|
||||
|
||||
* _traverse(suffix) {
|
||||
let result = [{router: this, path: [], suffix: suffix}];
|
||||
for (let route of traverse(this._tree, result, suffix, [])) {
|
||||
yield route;
|
||||
}
|
||||
}
|
||||
|
||||
_dispatch(rawReq, rawRes, context) {
|
||||
let route = resolve(this, rawReq);
|
||||
|
||||
|
@ -200,12 +179,25 @@ module.exports = class Router extends SwaggerContext {
|
|||
return false;
|
||||
}
|
||||
|
||||
let pathParams = {};
|
||||
let queryParams = _.clone(rawReq.queryParams);
|
||||
|
||||
const req = new SyntheticRequest(rawReq, context);
|
||||
const res = new SyntheticResponse(rawRes);
|
||||
|
||||
dispatch(route, req, res);
|
||||
return true;
|
||||
}
|
||||
|
||||
* _traverse(suffix) {
|
||||
let result = [{router: this, path: [], suffix: suffix}];
|
||||
for (let route of traverse(this._tree, result, suffix, [])) {
|
||||
yield route;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function dispatch(route, req, res) {
|
||||
let pathParams = {};
|
||||
let queryParams = _.clone(req.queryParams);
|
||||
|
||||
function next(err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
|
@ -249,9 +241,7 @@ module.exports = class Router extends SwaggerContext {
|
|||
}
|
||||
|
||||
next();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function applyPathParams(route) {
|
||||
for (const item of route) {
|
||||
|
|
Loading…
Reference in New Issue