@lwrjs/dev-proxy-server 0.12.0-alpha.3 → 0.12.0-alpha.31
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/build/cjs/index.cjs +1 -1
- package/build/cjs/middleware.cjs +15 -2
- package/build/es/index.js +1 -1
- package/build/es/middleware.d.ts +2 -2
- package/build/es/middleware.js +19 -3
- package/package.json +6 -6
package/build/cjs/index.cjs
CHANGED
|
@@ -50,7 +50,7 @@ function findProxyConfiguration(rootDir, buildDir) {
|
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
function readAndProcessProxyConfiguration(proxyConfigFile) {
|
|
53
|
-
const entries = import_fs.default.readFileSync(proxyConfigFile).toString().split("\n");
|
|
53
|
+
const entries = import_fs.default.readFileSync(proxyConfigFile).toString().trim().split("\n");
|
|
54
54
|
const proxyConfigs = entries.map((entry, idx) => {
|
|
55
55
|
const config = entry.split(" ");
|
|
56
56
|
if (config.length !== 2) {
|
package/build/cjs/middleware.cjs
CHANGED
|
@@ -38,8 +38,21 @@ var ProxyLogLevels;
|
|
|
38
38
|
ProxyLogLevels2["Error"] = "error";
|
|
39
39
|
ProxyLogLevels2["Silent"] = "silent";
|
|
40
40
|
})(ProxyLogLevels || (ProxyLogLevels = {}));
|
|
41
|
-
function addLocalProxyMiddleware(app,
|
|
42
|
-
|
|
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 forwarded = incomingRequest.headers.forwarded;
|
|
48
|
+
const hostHeader = incomingRequest.headers.host;
|
|
49
|
+
const hostProto = incomingRequest.protocol;
|
|
50
|
+
if (hostHeader !== domainAndPort) {
|
|
51
|
+
proxyRequest.setHeader(HOST, domainAndPort);
|
|
52
|
+
proxyRequest.setHeader("Forwarded", forwarded ? forwarded : `host=${hostHeader};proto=${hostProto}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
43
56
|
}
|
|
44
57
|
function addRemoteProxyMiddleware(app, proxyConfig) {
|
|
45
58
|
const {proxyConfigs} = proxyConfig;
|
package/build/es/index.js
CHANGED
|
@@ -37,7 +37,7 @@ export function findProxyConfiguration(rootDir, buildDir) {
|
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
function readAndProcessProxyConfiguration(proxyConfigFile) {
|
|
40
|
-
const entries = fs.readFileSync(proxyConfigFile).toString().split('\n');
|
|
40
|
+
const entries = fs.readFileSync(proxyConfigFile).toString().trim().split('\n');
|
|
41
41
|
const proxyConfigs = entries.map((entry, idx) => {
|
|
42
42
|
const config = entry.split(' ');
|
|
43
43
|
if (config.length !== 2) {
|
package/build/es/middleware.d.ts
CHANGED
|
@@ -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
|
|
6
|
+
* @param defaultHost
|
|
7
7
|
*/
|
|
8
|
-
export declare function addLocalProxyMiddleware(app: ExpressApp,
|
|
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
|
package/build/es/middleware.js
CHANGED
|
@@ -14,10 +14,26 @@ 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
|
|
17
|
+
* @param defaultHost
|
|
18
18
|
*/
|
|
19
|
-
export function addLocalProxyMiddleware(app,
|
|
20
|
-
|
|
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
|
+
// If a forwarded header is passed it should take precedence
|
|
26
|
+
const forwarded = incomingRequest.headers.forwarded;
|
|
27
|
+
// Host: <host>:<port>
|
|
28
|
+
const hostHeader = incomingRequest.headers.host;
|
|
29
|
+
const hostProto = incomingRequest.protocol;
|
|
30
|
+
if (hostHeader !== domainAndPort) {
|
|
31
|
+
proxyRequest.setHeader(HOST, domainAndPort);
|
|
32
|
+
// Add Forwarded header per https://git.soma.salesforce.com/pages/benjamin-fry/lwr-on-mrt-designs/request_path.html
|
|
33
|
+
proxyRequest.setHeader('Forwarded', forwarded ? forwarded : `host=${hostHeader};proto=${hostProto}`);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
}));
|
|
21
37
|
}
|
|
22
38
|
/**
|
|
23
39
|
* 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.
|
|
7
|
+
"version": "0.12.0-alpha.31",
|
|
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.
|
|
34
|
-
"@lwrjs/shared-utils": "0.12.0-alpha.
|
|
35
|
-
"express": "^4.
|
|
33
|
+
"@lwrjs/diagnostics": "0.12.0-alpha.31",
|
|
34
|
+
"@lwrjs/shared-utils": "0.12.0-alpha.31",
|
|
35
|
+
"express": "^4.19.2",
|
|
36
36
|
"http-proxy-middleware": "0.21.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@lwrjs/types": "0.12.0-alpha.
|
|
39
|
+
"@lwrjs/types": "0.12.0-alpha.31"
|
|
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": "
|
|
47
|
+
"gitHead": "ef2602996527852ec4694104723baae93a130b87"
|
|
48
48
|
}
|