@lwrjs/core 0.15.0-alpha.22 → 0.15.0-alpha.23

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) {
@@ -48,7 +48,7 @@ export function requestProcessorMiddleware(app, context) {
48
48
  // Return 400 Too Many Requests status
49
49
  return res.status(400).send('Request depth limit reached');
50
50
  }
51
- if (req.headers && typeof requestClass === 'string') {
51
+ if (req.headers && requestClass && typeof requestClass === 'string') {
52
52
  const parsedRequestClass = parseRequestClass(requestClass);
53
53
  logger.debug({
54
54
  label: `request-processor-middleware`,
@@ -58,15 +58,24 @@ export function requestProcessorMiddleware(app, context) {
58
58
  // If base path is '' or starts with / leave it alone
59
59
  req.basePath = pathValue === '' || pathValue.indexOf('/') === 0 ? pathValue : `/${pathValue}`;
60
60
  const expressRequest = req.req;
61
- if (expressRequest?.url?.startsWith(parsedRequestClass?.basePath)) {
62
- expressRequest.url = expressRequest.url.split(parsedRequestClass?.basePath)[1] || '/';
63
- expressRequest.originalUrl = expressRequest.url.split(parsedRequestClass?.basePath)[1] || '/';
64
- }
65
- else {
66
- logger.warn({
67
- label: `request-processor-middleware`,
68
- message: `The URL requested for doesn't start with the Base path`,
69
- });
61
+ // This section is code added for the 103 hints support. If CDN passes us a basePath in the header
62
+ // If the basePath is at the start of the URL we need to remove it so we can match the expected route.
63
+ if (expressRequest?.url && parsedRequestClass?.basePath) {
64
+ // Separate the path and the query param using dummy local host here since we do not use it
65
+ const { pathname, search } = new URL(expressRequest.url, 'http://localhost');
66
+ if (pathname.startsWith(parsedRequestClass.basePath)) {
67
+ // Remove the basePath from the pathname
68
+ const newPath = pathname.slice(parsedRequestClass.basePath.length) || '/';
69
+ // Reconstruct the URL with the modified path and original query string
70
+ expressRequest.url = newPath + search;
71
+ expressRequest.originalUrl = newPath + search;
72
+ }
73
+ else {
74
+ logger.warn({
75
+ label: `request-processor-middleware`,
76
+ message: `The URL requested for doesn't start with the Base path`,
77
+ });
78
+ }
70
79
  }
71
80
  }
72
81
  else {
@@ -81,6 +90,10 @@ export function requestProcessorMiddleware(app, context) {
81
90
  });
82
91
  }
83
92
  function parseRequestClass(requestClass) {
93
+ // If there is no requestClass do not bother parsing
94
+ if (!requestClass) {
95
+ return {};
96
+ }
84
97
  // Split the Forwarded header into individual key-value pairs
85
98
  const keyValuePairs = requestClass.split(';');
86
99
  // 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.15.0-alpha.22",
7
+ "version": "0.15.0-alpha.23",
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.15.0-alpha.22",
47
- "@lwrjs/asset-registry": "0.15.0-alpha.22",
48
- "@lwrjs/asset-transformer": "0.15.0-alpha.22",
49
- "@lwrjs/base-view-provider": "0.15.0-alpha.22",
50
- "@lwrjs/base-view-transformer": "0.15.0-alpha.22",
51
- "@lwrjs/client-modules": "0.15.0-alpha.22",
52
- "@lwrjs/config": "0.15.0-alpha.22",
53
- "@lwrjs/diagnostics": "0.15.0-alpha.22",
54
- "@lwrjs/esbuild": "0.15.0-alpha.22",
55
- "@lwrjs/fs-asset-provider": "0.15.0-alpha.22",
56
- "@lwrjs/fs-watch": "0.15.0-alpha.22",
57
- "@lwrjs/html-view-provider": "0.15.0-alpha.22",
58
- "@lwrjs/instrumentation": "0.15.0-alpha.22",
59
- "@lwrjs/loader": "0.15.0-alpha.22",
60
- "@lwrjs/lwc-module-provider": "0.15.0-alpha.22",
61
- "@lwrjs/lwc-ssr": "0.15.0-alpha.22",
62
- "@lwrjs/markdown-view-provider": "0.15.0-alpha.22",
63
- "@lwrjs/module-bundler": "0.15.0-alpha.22",
64
- "@lwrjs/module-registry": "0.15.0-alpha.22",
65
- "@lwrjs/npm-module-provider": "0.15.0-alpha.22",
66
- "@lwrjs/nunjucks-view-provider": "0.15.0-alpha.22",
67
- "@lwrjs/o11y": "0.15.0-alpha.22",
68
- "@lwrjs/resource-registry": "0.15.0-alpha.22",
69
- "@lwrjs/router": "0.15.0-alpha.22",
70
- "@lwrjs/server": "0.15.0-alpha.22",
71
- "@lwrjs/shared-utils": "0.15.0-alpha.22",
72
- "@lwrjs/static": "0.15.0-alpha.22",
73
- "@lwrjs/view-registry": "0.15.0-alpha.22",
46
+ "@lwrjs/app-service": "0.15.0-alpha.23",
47
+ "@lwrjs/asset-registry": "0.15.0-alpha.23",
48
+ "@lwrjs/asset-transformer": "0.15.0-alpha.23",
49
+ "@lwrjs/base-view-provider": "0.15.0-alpha.23",
50
+ "@lwrjs/base-view-transformer": "0.15.0-alpha.23",
51
+ "@lwrjs/client-modules": "0.15.0-alpha.23",
52
+ "@lwrjs/config": "0.15.0-alpha.23",
53
+ "@lwrjs/diagnostics": "0.15.0-alpha.23",
54
+ "@lwrjs/esbuild": "0.15.0-alpha.23",
55
+ "@lwrjs/fs-asset-provider": "0.15.0-alpha.23",
56
+ "@lwrjs/fs-watch": "0.15.0-alpha.23",
57
+ "@lwrjs/html-view-provider": "0.15.0-alpha.23",
58
+ "@lwrjs/instrumentation": "0.15.0-alpha.23",
59
+ "@lwrjs/loader": "0.15.0-alpha.23",
60
+ "@lwrjs/lwc-module-provider": "0.15.0-alpha.23",
61
+ "@lwrjs/lwc-ssr": "0.15.0-alpha.23",
62
+ "@lwrjs/markdown-view-provider": "0.15.0-alpha.23",
63
+ "@lwrjs/module-bundler": "0.15.0-alpha.23",
64
+ "@lwrjs/module-registry": "0.15.0-alpha.23",
65
+ "@lwrjs/npm-module-provider": "0.15.0-alpha.23",
66
+ "@lwrjs/nunjucks-view-provider": "0.15.0-alpha.23",
67
+ "@lwrjs/o11y": "0.15.0-alpha.23",
68
+ "@lwrjs/resource-registry": "0.15.0-alpha.23",
69
+ "@lwrjs/router": "0.15.0-alpha.23",
70
+ "@lwrjs/server": "0.15.0-alpha.23",
71
+ "@lwrjs/shared-utils": "0.15.0-alpha.23",
72
+ "@lwrjs/static": "0.15.0-alpha.23",
73
+ "@lwrjs/view-registry": "0.15.0-alpha.23",
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.15.0-alpha.22",
83
+ "@lwrjs/types": "0.15.0-alpha.23",
84
84
  "@types/ws": "^8.5.12",
85
85
  "memfs": "^4.9.3"
86
86
  },
@@ -93,5 +93,5 @@
93
93
  "volta": {
94
94
  "extends": "../../../package.json"
95
95
  },
96
- "gitHead": "0c89221b041a09f05fe6463ad385941f0351dbbe"
96
+ "gitHead": "07592ebcbcfd739a9a8882b2f8f56da50332250d"
97
97
  }