@lwrjs/dev-proxy-server 0.12.0-alpha.3 → 0.12.0-alpha.4

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.
@@ -38,8 +38,19 @@ var ProxyLogLevels;
38
38
  ProxyLogLevels2["Error"] = "error";
39
39
  ProxyLogLevels2["Silent"] = "silent";
40
40
  })(ProxyLogLevels || (ProxyLogLevels = {}));
41
- function addLocalProxyMiddleware(app, localHost) {
42
- app.use("/", (0, import_http_proxy_middleware.default)({target: localHost, changeOrigin: true}));
41
+ function addLocalProxyMiddleware(app, defaultHost) {
42
+ const domainAndPort = defaultHost.replace(/^([a-z][a-z0-9+\-.]*):\/\//, "");
43
+ app.use("/", (0, import_http_proxy_middleware.default)({
44
+ target: defaultHost,
45
+ changeOrigin: true,
46
+ onProxyReq: (proxyRequest, incomingRequest) => {
47
+ const hostHeader = incomingRequest.headers.host;
48
+ if (hostHeader !== domainAndPort) {
49
+ proxyRequest.setHeader(HOST, domainAndPort);
50
+ proxyRequest.setHeader("Forwarded", `host=${hostHeader}`);
51
+ }
52
+ }
53
+ }));
43
54
  }
44
55
  function addRemoteProxyMiddleware(app, proxyConfig) {
45
56
  const {proxyConfigs} = proxyConfig;
@@ -3,9 +3,9 @@ import type { ProxyConfiguration } from './proxy-server.js';
3
3
  /**
4
4
  * The Proxy middleware responsible for proxying all other requests not configured to external systems.
5
5
  * @param app
6
- * @param localHost
6
+ * @param defaultHost
7
7
  */
8
- export declare function addLocalProxyMiddleware(app: ExpressApp, localHost: string): void;
8
+ export declare function addLocalProxyMiddleware(app: ExpressApp, defaultHost: string): void;
9
9
  /**
10
10
  * The Proxy middleware responsible for proxying requests to a configured remote origin.
11
11
  * @param app
@@ -14,10 +14,23 @@ var ProxyLogLevels;
14
14
  /**
15
15
  * The Proxy middleware responsible for proxying all other requests not configured to external systems.
16
16
  * @param app
17
- * @param localHost
17
+ * @param defaultHost
18
18
  */
19
- export function addLocalProxyMiddleware(app, localHost) {
20
- app.use('/', proxy({ target: localHost, changeOrigin: true }));
19
+ export function addLocalProxyMiddleware(app, defaultHost) {
20
+ const domainAndPort = defaultHost.replace(/^([a-z][a-z0-9+\-.]*):\/\//, '');
21
+ app.use('/', proxy({
22
+ target: defaultHost,
23
+ changeOrigin: true,
24
+ onProxyReq: (proxyRequest, incomingRequest) => {
25
+ // Host: <host>:<port>
26
+ const hostHeader = incomingRequest.headers.host;
27
+ if (hostHeader !== domainAndPort) {
28
+ proxyRequest.setHeader(HOST, domainAndPort);
29
+ // Add Forwarded header per https://git.soma.salesforce.com/pages/benjamin-fry/lwr-on-mrt-designs/request_path.html
30
+ proxyRequest.setHeader('Forwarded', `host=${hostHeader}`);
31
+ }
32
+ },
33
+ }));
21
34
  }
22
35
  /**
23
36
  * The Proxy middleware responsible for proxying requests to a configured remote origin.
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.12.0-alpha.3",
7
+ "version": "0.12.0-alpha.4",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -30,13 +30,13 @@
30
30
  "build/**/*.d.ts"
31
31
  ],
32
32
  "dependencies": {
33
- "@lwrjs/diagnostics": "0.12.0-alpha.3",
34
- "@lwrjs/shared-utils": "0.12.0-alpha.3",
33
+ "@lwrjs/diagnostics": "0.12.0-alpha.4",
34
+ "@lwrjs/shared-utils": "0.12.0-alpha.4",
35
35
  "express": "^4.18.2",
36
36
  "http-proxy-middleware": "0.21.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@lwrjs/types": "0.12.0-alpha.3"
39
+ "@lwrjs/types": "0.12.0-alpha.4"
40
40
  },
41
41
  "engines": {
42
42
  "node": ">=18.0.0"
@@ -44,5 +44,5 @@
44
44
  "volta": {
45
45
  "extends": "../../../package.json"
46
46
  },
47
- "gitHead": "48f97b40cbacce6cd6a6faee9206a465832c6774"
47
+ "gitHead": "7b68e0ffa5e4d61ae97a4b020f9690ee7b08d5da"
48
48
  }