webpack-mock-server
Version:
Mocks api requests for webpack-dev-server with hot-replacement
37 lines (36 loc) • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = provideRoutes;
function provideRoutes(app, exlcudePath) {
const routes = [];
function normalizeInfo(path, methods) {
if (path !== exlcudePath) {
routes.push({
method: Object.keys(methods)
.filter((key) => methods[key])
.join(","),
path,
});
}
}
app._router.stack.forEach((r) => {
if (r.route && r.route.path) {
const { path } = r.route;
const { methods } = r.route;
if (Array.isArray(path)) {
path.forEach((v) => normalizeInfo(v, methods));
}
else {
normalizeInfo(path, methods);
}
}
});
function stringCompare(v1, v2) {
return v1.localeCompare(v2, undefined, {
sensitivity: "base",
ignorePunctuation: true,
numeric: true,
});
}
return routes.sort((v1, v2) => stringCompare(v1.method, v2.method) || stringCompare(v1.path, v2.path));
}