@lwrjs/core 0.13.9 → 0.13.10

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.
@@ -64,7 +64,7 @@ function requestProcessorMiddleware(app, context) {
64
64
  });
65
65
  return res.status(400).send("Request depth limit reached");
66
66
  }
67
- if (req.headers && typeof requestClass === "string") {
67
+ if (req.headers && requestClass && typeof requestClass === "string") {
68
68
  const parsedRequestClass = parseRequestClass(requestClass);
69
69
  import_diagnostics.logger.debug({
70
70
  label: `request-processor-middleware`,
@@ -73,14 +73,18 @@ function requestProcessorMiddleware(app, context) {
73
73
  const pathValue = parsedRequestClass?.basePath || basePath || "";
74
74
  req.basePath = pathValue === "" || pathValue.indexOf("/") === 0 ? pathValue : `/${pathValue}`;
75
75
  const expressRequest = req.req;
76
- if (expressRequest?.url?.startsWith(parsedRequestClass?.basePath)) {
77
- expressRequest.url = expressRequest.url.split(parsedRequestClass?.basePath)[1] || "/";
78
- expressRequest.originalUrl = expressRequest.url.split(parsedRequestClass?.basePath)[1] || "/";
79
- } else {
80
- import_diagnostics.logger.warn({
81
- label: `request-processor-middleware`,
82
- message: `The URL requested for doesn't start with the Base path`
83
- });
76
+ if (expressRequest?.url && parsedRequestClass?.basePath) {
77
+ const {pathname, search} = new URL(expressRequest.url, "http://localhost");
78
+ if (pathname.startsWith(parsedRequestClass.basePath)) {
79
+ const newPath = pathname.slice(parsedRequestClass.basePath.length) || "/";
80
+ expressRequest.url = newPath + search;
81
+ expressRequest.originalUrl = newPath + search;
82
+ } else {
83
+ import_diagnostics.logger.warn({
84
+ label: `request-processor-middleware`,
85
+ message: `The URL requested for doesn't start with the Base path`
86
+ });
87
+ }
84
88
  }
85
89
  } else {
86
90
  import_diagnostics.logger.debug({
@@ -93,6 +97,9 @@ function requestProcessorMiddleware(app, context) {
93
97
  });
94
98
  }
95
99
  function parseRequestClass(requestClass) {
100
+ if (!requestClass) {
101
+ return {};
102
+ }
96
103
  const keyValuePairs = requestClass.split(";");
97
104
  const parsed = {};
98
105
  for (const pair of keyValuePairs) {
@@ -49,7 +49,7 @@ export function requestProcessorMiddleware(app, context) {
49
49
  // Return 400 Too Many Requests status
50
50
  return res.status(400).send('Request depth limit reached');
51
51
  }
52
- if (req.headers && typeof requestClass === 'string') {
52
+ if (req.headers && requestClass && typeof requestClass === 'string') {
53
53
  const parsedRequestClass = parseRequestClass(requestClass);
54
54
  logger.debug({
55
55
  label: `request-processor-middleware`,
@@ -59,15 +59,24 @@ export function requestProcessorMiddleware(app, context) {
59
59
  // If base path is '' or starts with / leave it alone
60
60
  req.basePath = pathValue === '' || pathValue.indexOf('/') === 0 ? pathValue : `/${pathValue}`;
61
61
  const expressRequest = req.req;
62
- if (expressRequest?.url?.startsWith(parsedRequestClass?.basePath)) {
63
- expressRequest.url = expressRequest.url.split(parsedRequestClass?.basePath)[1] || '/';
64
- expressRequest.originalUrl = expressRequest.url.split(parsedRequestClass?.basePath)[1] || '/';
65
- }
66
- else {
67
- logger.warn({
68
- label: `request-processor-middleware`,
69
- message: `The URL requested for doesn't start with the Base path`,
70
- });
62
+ // This section is code added for the 103 hints support. If CDN passes us a basePath in the header
63
+ // If the basePath is at the start of the URL we need to remove it so we can match the expected route.
64
+ if (expressRequest?.url && parsedRequestClass?.basePath) {
65
+ // Separate the path and the query param using dummy local host here since we do not use it
66
+ const { pathname, search } = new URL(expressRequest.url, 'http://localhost');
67
+ if (pathname.startsWith(parsedRequestClass.basePath)) {
68
+ // Remove the basePath from the pathname
69
+ const newPath = pathname.slice(parsedRequestClass.basePath.length) || '/';
70
+ // Reconstruct the URL with the modified path and original query string
71
+ expressRequest.url = newPath + search;
72
+ expressRequest.originalUrl = newPath + search;
73
+ }
74
+ else {
75
+ logger.warn({
76
+ label: `request-processor-middleware`,
77
+ message: `The URL requested for doesn't start with the Base path`,
78
+ });
79
+ }
71
80
  }
72
81
  }
73
82
  else {
@@ -82,6 +91,10 @@ export function requestProcessorMiddleware(app, context) {
82
91
  });
83
92
  }
84
93
  function parseRequestClass(requestClass) {
94
+ // If there is no requestClass do not bother parsing
95
+ if (!requestClass) {
96
+ return {};
97
+ }
85
98
  // Split the Forwarded header into individual key-value pairs
86
99
  const keyValuePairs = requestClass.split(';');
87
100
  // Create an object to store the parsed values
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.13.9",
7
+ "version": "0.13.10",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -43,34 +43,34 @@
43
43
  "build": "tsc -b"
44
44
  },
45
45
  "dependencies": {
46
- "@lwrjs/app-service": "0.13.9",
47
- "@lwrjs/asset-registry": "0.13.9",
48
- "@lwrjs/asset-transformer": "0.13.9",
49
- "@lwrjs/base-view-provider": "0.13.9",
50
- "@lwrjs/base-view-transformer": "0.13.9",
51
- "@lwrjs/client-modules": "0.13.9",
52
- "@lwrjs/config": "0.13.9",
53
- "@lwrjs/diagnostics": "0.13.9",
54
- "@lwrjs/esbuild": "0.13.9",
55
- "@lwrjs/fs-asset-provider": "0.13.9",
56
- "@lwrjs/fs-watch": "0.13.9",
57
- "@lwrjs/html-view-provider": "0.13.9",
58
- "@lwrjs/instrumentation": "0.13.9",
59
- "@lwrjs/loader": "0.13.9",
60
- "@lwrjs/lwc-module-provider": "0.13.9",
61
- "@lwrjs/lwc-ssr": "0.13.9",
62
- "@lwrjs/markdown-view-provider": "0.13.9",
63
- "@lwrjs/module-bundler": "0.13.9",
64
- "@lwrjs/module-registry": "0.13.9",
65
- "@lwrjs/npm-module-provider": "0.13.9",
66
- "@lwrjs/nunjucks-view-provider": "0.13.9",
67
- "@lwrjs/o11y": "0.13.9",
68
- "@lwrjs/resource-registry": "0.13.9",
69
- "@lwrjs/router": "0.13.9",
70
- "@lwrjs/server": "0.13.9",
71
- "@lwrjs/shared-utils": "0.13.9",
72
- "@lwrjs/static": "0.13.9",
73
- "@lwrjs/view-registry": "0.13.9",
46
+ "@lwrjs/app-service": "0.13.10",
47
+ "@lwrjs/asset-registry": "0.13.10",
48
+ "@lwrjs/asset-transformer": "0.13.10",
49
+ "@lwrjs/base-view-provider": "0.13.10",
50
+ "@lwrjs/base-view-transformer": "0.13.10",
51
+ "@lwrjs/client-modules": "0.13.10",
52
+ "@lwrjs/config": "0.13.10",
53
+ "@lwrjs/diagnostics": "0.13.10",
54
+ "@lwrjs/esbuild": "0.13.10",
55
+ "@lwrjs/fs-asset-provider": "0.13.10",
56
+ "@lwrjs/fs-watch": "0.13.10",
57
+ "@lwrjs/html-view-provider": "0.13.10",
58
+ "@lwrjs/instrumentation": "0.13.10",
59
+ "@lwrjs/loader": "0.13.10",
60
+ "@lwrjs/lwc-module-provider": "0.13.10",
61
+ "@lwrjs/lwc-ssr": "0.13.10",
62
+ "@lwrjs/markdown-view-provider": "0.13.10",
63
+ "@lwrjs/module-bundler": "0.13.10",
64
+ "@lwrjs/module-registry": "0.13.10",
65
+ "@lwrjs/npm-module-provider": "0.13.10",
66
+ "@lwrjs/nunjucks-view-provider": "0.13.10",
67
+ "@lwrjs/o11y": "0.13.10",
68
+ "@lwrjs/resource-registry": "0.13.10",
69
+ "@lwrjs/router": "0.13.10",
70
+ "@lwrjs/server": "0.13.10",
71
+ "@lwrjs/shared-utils": "0.13.10",
72
+ "@lwrjs/static": "0.13.10",
73
+ "@lwrjs/view-registry": "0.13.10",
74
74
  "chokidar": "^3.6.0",
75
75
  "esbuild": "^0.9.7",
76
76
  "fs-extra": "^11.2.0",
@@ -80,7 +80,7 @@
80
80
  "ws": "^8.18.0"
81
81
  },
82
82
  "devDependencies": {
83
- "@lwrjs/types": "0.13.9",
83
+ "@lwrjs/types": "0.13.10",
84
84
  "@types/ws": "^8.5.10",
85
85
  "memfs": "^4.9.3"
86
86
  },
@@ -93,5 +93,5 @@
93
93
  "volta": {
94
94
  "extends": "../../../package.json"
95
95
  },
96
- "gitHead": "c991b71930739c3ac1f411b361a09ac777f7eeb3"
96
+ "gitHead": "45dfe095e39f71b14e110ede777b9bf66c929475"
97
97
  }