mirror of https://gitee.com/bigwinds/arangodb
Spring cleaning
Also removed actions.rewriteRouting as it is not actually used anywhere.
This commit is contained in:
parent
8c9dd79aeb
commit
2eb8f30c7f
|
@ -511,7 +511,7 @@ function splitUrl (url) {
|
|||
parts = url.split('/');
|
||||
cleaned = [];
|
||||
|
||||
for (i = 0; i < parts.length; ++i) {
|
||||
for (i = 0; i < parts.length; i++) {
|
||||
var part = parts[i];
|
||||
|
||||
if (part !== '' && part !== '.') {
|
||||
|
@ -639,7 +639,7 @@ function defineRoutePart (storage, route, parts, pos, constraint, callback) {
|
|||
}
|
||||
|
||||
if (ok) {
|
||||
for (i = 0; i < part.parameters.length; ++i) {
|
||||
for (i = 0; i < part.parameters.length; i++) {
|
||||
var p = part.parameters[i];
|
||||
var subsub = { parameter: p, match: {} };
|
||||
storage.parameters.push(subsub);
|
||||
|
@ -710,7 +710,7 @@ function intersectMethods (a, b) {
|
|||
a = a || ALL_METHODS;
|
||||
b = b || ALL_METHODS;
|
||||
|
||||
for (i = 0; i < b.length; i++) {
|
||||
for (i = 0; i < b.length; i++) {
|
||||
d[b[i].toUpperCase()] = true;
|
||||
}
|
||||
|
||||
|
@ -736,7 +736,7 @@ function defineRoute (storage, route, url, callback) {
|
|||
|
||||
var methods = intersectMethods(url.methods, callback.methods);
|
||||
|
||||
for (j = 0; j < methods.length; ++j) {
|
||||
for (j = 0; j < methods.length; j++) {
|
||||
var method = methods[j];
|
||||
|
||||
defineRoutePart(storage[method], route, url.urlParts, 0, url.constraint, callback);
|
||||
|
@ -787,13 +787,13 @@ function analyseRoutes (storage, routes) {
|
|||
// install the routes
|
||||
var keys = [ 'routes', 'middleware' ];
|
||||
|
||||
for (j = 0; j < keys.length; ++j) {
|
||||
for (j = 0; j < keys.length; j++) {
|
||||
var key = keys[j];
|
||||
|
||||
if (routes.hasOwnProperty(key)) {
|
||||
var r = routes[key];
|
||||
|
||||
for (i = 0; i < r.length; ++i) {
|
||||
for (i = 0; i < r.length; i++) {
|
||||
installRoute(storage[key],
|
||||
r[i],
|
||||
urlPrefix,
|
||||
|
@ -814,14 +814,14 @@ function buildRoutingTree (routes) {
|
|||
|
||||
var storage = { routes: {}, middleware: {} };
|
||||
|
||||
for (j = 0; j < ALL_METHODS.length; ++j) {
|
||||
for (j = 0; j < ALL_METHODS.length; j++) {
|
||||
var method = ALL_METHODS[j];
|
||||
|
||||
storage.routes[method] = {};
|
||||
storage.middleware[method] = {};
|
||||
}
|
||||
|
||||
for (j = 0; j < routes.length; ++j) {
|
||||
for (j = 0; j < routes.length; j++) {
|
||||
var route = routes[j];
|
||||
|
||||
try {
|
||||
|
@ -883,7 +883,7 @@ function flattenRouting (routes, path, rexpr, urlParameters, depth, prefix) {
|
|||
// .............................................................................
|
||||
|
||||
if (routes.hasOwnProperty('parameters')) {
|
||||
for (i = 0; i < routes.parameters.length; ++i) {
|
||||
for (i = 0; i < routes.parameters.length; i++) {
|
||||
parameter = routes.parameters[i];
|
||||
|
||||
if (parameter.hasOwnProperty('constraint')) {
|
||||
|
@ -927,7 +927,7 @@ function flattenRouting (routes, path, rexpr, urlParameters, depth, prefix) {
|
|||
return b.priority - a.priority;
|
||||
})];
|
||||
|
||||
for (i = 0; i < sorted.length; ++i) {
|
||||
for (i = 0; i < sorted.length; i++) {
|
||||
sorted[i] = {
|
||||
path: path,
|
||||
regexp: new RegExp('^' + rexpr + '$'),
|
||||
|
@ -970,7 +970,7 @@ function flattenRoutingTree (tree) {
|
|||
|
||||
var flat = {};
|
||||
|
||||
for (i = 0; i < ALL_METHODS.length; ++i) {
|
||||
for (i = 0; i < ALL_METHODS.length; i++) {
|
||||
var method = ALL_METHODS[i];
|
||||
|
||||
var a = flattenRouting(tree.routes[method], '', '', {}, 0, false);
|
||||
|
@ -1067,7 +1067,7 @@ function buildRouting (dbname) {
|
|||
// install the foxx routes
|
||||
var foxxes = foxxManager.mountPoints();
|
||||
|
||||
for (let i = 0; i < foxxes.length; ++i) {
|
||||
for (let i = 0; i < foxxes.length; i++) {
|
||||
var foxx = foxxes[i];
|
||||
|
||||
routes.push({
|
||||
|
@ -1094,7 +1094,7 @@ function nextRouting (state) {
|
|||
var i;
|
||||
var k;
|
||||
|
||||
for (i = state.position + 1; i < state.routing.length; ++i) {
|
||||
for (i = state.position + 1; i < state.routing.length; i++) {
|
||||
var route = state.routing[i];
|
||||
|
||||
if (route.regexp.test(state.url)) {
|
||||
|
@ -1138,33 +1138,23 @@ function nextRouting (state) {
|
|||
function firstRouting (type, parts, routes) {
|
||||
'use strict';
|
||||
|
||||
var url = parts;
|
||||
|
||||
if (typeof url === 'string') {
|
||||
parts = url.split('/');
|
||||
|
||||
if (parts[0] === '') {
|
||||
parts.shift();
|
||||
}
|
||||
} else {
|
||||
url = '/' + parts.join('/');
|
||||
}
|
||||
var url = '/' + parts.join('/');
|
||||
|
||||
if (!routes || !routes.hasOwnProperty(type)) {
|
||||
return {
|
||||
parts: parts,
|
||||
position: -1,
|
||||
url: url,
|
||||
urlParameters: {}
|
||||
urlParameters: {},
|
||||
parts,
|
||||
url
|
||||
};
|
||||
}
|
||||
|
||||
return nextRouting({
|
||||
routing: routes[type],
|
||||
parts: parts,
|
||||
position: -1,
|
||||
url: url,
|
||||
urlParameters: {}
|
||||
urlParameters: {},
|
||||
parts,
|
||||
url
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1290,7 +1280,7 @@ function startup () {
|
|||
var actions = fs.listTree(actionPath);
|
||||
var i;
|
||||
|
||||
for (i = 0; i < actions.length; ++i) {
|
||||
for (i = 0; i < actions.length; i++) {
|
||||
var file = actions[i];
|
||||
var full = fs.join(actionPath, file);
|
||||
|
||||
|
@ -1989,31 +1979,6 @@ function redirectRequest (req, res, options, next) {
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
// @brief rewrites a request
|
||||
//
|
||||
|
||||
function rewriteRequest (req, res, options, next) {
|
||||
'use strict';
|
||||
|
||||
var i = 0;
|
||||
var suffix = options.destination.split('/');
|
||||
|
||||
for (i = 0; i < suffix.length; ++i) {
|
||||
if (suffix[i] !== '') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 < i) {
|
||||
suffix = suffix.splice(i);
|
||||
}
|
||||
|
||||
req.suffix = suffix;
|
||||
|
||||
next(true);
|
||||
}
|
||||
|
||||
//
|
||||
// @brief redirects a request
|
||||
//
|
||||
|
@ -2073,18 +2038,21 @@ exports.startup = startup;
|
|||
exports.buildRouting = buildRouting;
|
||||
exports.buildRoutingTree = buildRoutingTree;
|
||||
exports.flattenRoutingTree = flattenRoutingTree;
|
||||
exports.routingTree = function () { return RoutingTree; };
|
||||
exports.routingList = function () { return RoutingList; };
|
||||
exports.nextRouting = nextRouting;
|
||||
exports.firstRouting = function firstRouting (method, url, routes) {
|
||||
const parts = url.split('/').filter(s => s !== '');
|
||||
return firstRouting(method, parts, routes);
|
||||
};
|
||||
|
||||
// public functions
|
||||
exports.routingTree = () => RoutingTree;
|
||||
exports.routingList = () => RoutingList;
|
||||
exports.routeRequest = routeRequest;
|
||||
exports.defineHttp = defineHttp;
|
||||
exports.getErrorMessage = getErrorMessage;
|
||||
exports.getJsonBody = getJsonBody;
|
||||
exports.errorFunction = errorFunction;
|
||||
exports.reloadRouting = reloadRouting;
|
||||
exports.firstRouting = firstRouting;
|
||||
exports.nextRouting = nextRouting;
|
||||
exports.addCookie = addCookie;
|
||||
exports.stringifyRequest = stringifyRequest;
|
||||
exports.arangoErrorToHttpCode = arangoErrorToHttpCode;
|
||||
|
@ -2111,7 +2079,6 @@ exports.easyPostCallback = easyPostCallback;
|
|||
exports.echoRequest = echoRequest;
|
||||
exports.logRequest = logRequest;
|
||||
exports.redirectRequest = redirectRequest;
|
||||
exports.rewriteRequest = rewriteRequest;
|
||||
exports.pathHandler = pathHandler;
|
||||
|
||||
// some useful constants
|
||||
|
|
|
@ -81,11 +81,11 @@ module.exports =
|
|||
|
||||
* findRoutes (suffix) {
|
||||
const result = [{router: this.router, path: [], suffix: suffix}];
|
||||
yield* findRoutes(this.root, result, suffix, []);
|
||||
yield * findRoutes(this.root, result, suffix, []);
|
||||
}
|
||||
|
||||
* flatten () {
|
||||
yield* flatten(this.root, [this.router]);
|
||||
yield * flatten(this.root, [this.router]);
|
||||
}
|
||||
|
||||
resolve (rawReq) {
|
||||
|
@ -459,7 +459,7 @@ function * findRoutes (node, result, suffix, path) {
|
|||
const suffix2 = suffix.slice(1);
|
||||
for (const childNode of [node.get(part), node.get(tokenize.PARAM)]) {
|
||||
if (childNode) {
|
||||
yield* findRoutes(childNode, result, suffix2, path2);
|
||||
yield * findRoutes(childNode, result, suffix2, path2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -472,7 +472,7 @@ function * findRoutes (node, result, suffix, path) {
|
|||
{router: endpoint, path: path, suffix: suffix}
|
||||
);
|
||||
const path2 = [];
|
||||
yield* findRoutes(childNode, result2, suffix, path2);
|
||||
yield * findRoutes(childNode, result2, suffix, path2);
|
||||
} else {
|
||||
yield result.concat(
|
||||
{endpoint: endpoint, path: path, suffix: suffix}
|
||||
|
@ -491,13 +491,13 @@ function * flatten (node, result) {
|
|||
}
|
||||
for (const endpoint of child.get($_ROUTES) || []) {
|
||||
if (endpoint.router) {
|
||||
yield* flatten(endpoint.tree.root, result.concat(endpoint, endpoint.router));
|
||||
yield * flatten(endpoint.tree.root, result.concat(endpoint, endpoint.router));
|
||||
} else {
|
||||
yield result.concat(endpoint);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
yield* flatten(child, result);
|
||||
yield * flatten(child, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ function routingSuiteSingle () {
|
|||
|
||||
routing = flattenRoutingTree(buildRoutingTree(routes));
|
||||
},
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test: simple routing
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue