-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (30 loc) · 1.35 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
var express = require('express');
exports.getAppRoutes = function(expressApp) {
// TBD - recurse over route tree to replace triple loop.
const result = [];
expressApp._router.stack.forEach(layer => {
if (layer.route) {
result.push(layer);
} else if (layer.name === 'router') {
const regexp = layer.regexp.source;
const prefix_routes = regexp.match(/(\w+)+/gi);
let prefix = '';
if (prefix_routes !== null) {
prefix_routes.forEach(prefix_route => {
prefix += `/${prefix_route}`
});
}
layer.handle.stack.forEach(handler => {
if (handler.route.stack) {
handler.route.stack.forEach(endRoute => {
const method = endRoute.method ? endRoute.method.toUpperCase() : null;
const route = handler.route.path;
result.push({method: method, path: prefix + route});
});
}
});
}
});
return result;
};