mastercontroller 1.3.17 → 1.3.18
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.
- package/MasterRouter.js +25 -0
- package/package.json +1 -1
package/MasterRouter.js
CHANGED
|
@@ -908,7 +908,32 @@ class MasterRouter {
|
|
|
908
908
|
throw new TypeError('Request object must have a valid response property');
|
|
909
909
|
}
|
|
910
910
|
|
|
911
|
+
// Normalize pathName from various request object formats
|
|
911
912
|
if (!rr.pathName || typeof rr.pathName !== 'string') {
|
|
913
|
+
// Try to extract pathName from standard HTTP request properties
|
|
914
|
+
if (rr.request.url) {
|
|
915
|
+
// Handle full URL or path with query string (Node.js http, Express)
|
|
916
|
+
try {
|
|
917
|
+
// Try parsing as full URL first
|
|
918
|
+
const url = new URL(rr.request.url, `http://${rr.request.headers?.host || 'localhost'}`);
|
|
919
|
+
rr.pathName = url.pathname;
|
|
920
|
+
} catch (e) {
|
|
921
|
+
// Fallback: treat as relative path, strip query string
|
|
922
|
+
rr.pathName = rr.request.url.split('?')[0];
|
|
923
|
+
}
|
|
924
|
+
} else if (rr.request.path) {
|
|
925
|
+
// Express-style request.path
|
|
926
|
+
rr.pathName = rr.request.path;
|
|
927
|
+
} else if (rr.request.pathname) {
|
|
928
|
+
// Alternative property name
|
|
929
|
+
rr.pathName = rr.request.pathname;
|
|
930
|
+
} else {
|
|
931
|
+
throw new TypeError('Request object must have a valid path (url, path, pathname, or pathName property)');
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// Validate that we now have a valid pathName
|
|
936
|
+
if (typeof rr.pathName !== 'string') {
|
|
912
937
|
throw new TypeError('Request object must have a valid pathName');
|
|
913
938
|
}
|
|
914
939
|
|
package/package.json
CHANGED