mastercontroller 1.3.16 → 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.
Files changed (2) hide show
  1. package/MasterRouter.js +31 -2
  2. package/package.json +1 -1
package/MasterRouter.js CHANGED
@@ -89,7 +89,9 @@ const ROUTER_CONFIG = {
89
89
  const sanitizedValue = sanitizeRouteParam(paramName, paramValue);
90
90
 
91
91
  requestParams[paramName] = sanitizedValue;
92
- routePathList[i] = sanitizedValue;
92
+ // FIX: Use requestItem (original value) not sanitizedValue for route matching
93
+ // The route pattern should match against the actual request path
94
+ routePathList[i] = requestItem;
93
95
  }
94
96
  }
95
97
  }
@@ -906,7 +908,32 @@ class MasterRouter {
906
908
  throw new TypeError('Request object must have a valid response property');
907
909
  }
908
910
 
911
+ // Normalize pathName from various request object formats
909
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') {
910
937
  throw new TypeError('Request object must have a valid pathName');
911
938
  }
912
939
 
@@ -915,7 +942,9 @@ class MasterRouter {
915
942
  }
916
943
 
917
944
  const $that = this;
918
- const requestObject = Object.create(rr);
945
+ // FIX: Use direct reference instead of Object.create() to preserve request/response objects
946
+ // Object.create() puts properties on prototype, causing undefined access issues
947
+ const requestObject = rr;
919
948
 
920
949
  // CRITICAL FIX: Load scoped services into request-specific context
921
950
  // Pass requestObject so scoped services are stored per-request, not globally
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mastercontroller",
3
- "version": "1.3.16",
3
+ "version": "1.3.18",
4
4
  "description": "Fortune 500 ready Node.js MVC framework with enterprise security, monitoring, and horizontal scaling",
5
5
  "main": "MasterControl.js",
6
6
  "license": "MIT",