mock-config-server 3.6.0 → 3.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -34,7 +34,31 @@ const calculateRouteConfigWeight = (restRouteConfig)=>{
|
|
|
34
34
|
return routeConfigWeight;
|
|
35
35
|
};
|
|
36
36
|
const prepareRestRequestConfigs = (requestConfigs)=>{
|
|
37
|
-
requestConfigs.
|
|
37
|
+
const sortedByPathRequestConfigs = requestConfigs.sort(({ path: firstPath }, { path: secondPath })=>{
|
|
38
|
+
// ✅ important:
|
|
39
|
+
// do not compare RegExp paths and non-parameterized paths
|
|
40
|
+
if (firstPath instanceof RegExp || secondPath instanceof RegExp) return 0;
|
|
41
|
+
if (!firstPath.includes('/:') && !secondPath.includes('/:')) return 0;
|
|
42
|
+
const firstPathParts = firstPath.split('/');
|
|
43
|
+
const secondPathParts = secondPath.split('/');
|
|
44
|
+
const minimalPathPartsLength = Math.min(firstPathParts.length, secondPathParts.length);
|
|
45
|
+
// ✅ important:
|
|
46
|
+
// need to find the leftmost parameter/non-parameter pair and give priority to non-parameter one
|
|
47
|
+
for(let i = 0; i < minimalPathPartsLength; i += 1){
|
|
48
|
+
const firstPathPart = firstPathParts[i];
|
|
49
|
+
const secondPathPart = secondPathParts[i];
|
|
50
|
+
const isFirstPathPartParameter = firstPathPart.startsWith(':');
|
|
51
|
+
const isSecondPathPartParameter = secondPathPart.startsWith(':');
|
|
52
|
+
if (!isFirstPathPartParameter && !isSecondPathPartParameter) {
|
|
53
|
+
if (firstPathPart === secondPathPart) continue;
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
if (isFirstPathPartParameter && isSecondPathPartParameter) continue;
|
|
57
|
+
return +isFirstPathPartParameter - +isSecondPathPartParameter;
|
|
58
|
+
}
|
|
59
|
+
return 0;
|
|
60
|
+
});
|
|
61
|
+
sortedByPathRequestConfigs.forEach((requestConfig)=>{
|
|
38
62
|
requestConfig.routes.sort((first, second)=>// ✅ important:
|
|
39
63
|
// Lift more specific configs for correct working of routes
|
|
40
64
|
calculateRouteConfigWeight(second) - calculateRouteConfigWeight(first));
|