@lwrjs/dev-proxy-server 0.15.0-alpha.39 → 0.15.0-alpha.40
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/middleware.cjs +17 -0
- package/build/es/middleware.js +26 -0
- package/package.json +5 -5
package/build/cjs/middleware.cjs
CHANGED
|
@@ -80,6 +80,23 @@ function addRemoteProxyMiddleware(app, proxyConfig) {
|
|
|
80
80
|
proxyRequest.setHeader("Forwarded", `host=${hostHeader}`);
|
|
81
81
|
const originalPath = incomingRequest.url;
|
|
82
82
|
proxyRequest.path = originalPath;
|
|
83
|
+
if (process.env.AUTH_TOKEN) {
|
|
84
|
+
let cookies = proxyRequest.getHeader("cookie") || "";
|
|
85
|
+
const sidCookie = `__Secure-has-sid=1; sid=${process.env.AUTH_TOKEN};`;
|
|
86
|
+
if (cookies) {
|
|
87
|
+
cookies += `; ${sidCookie}`;
|
|
88
|
+
} else {
|
|
89
|
+
cookies = sidCookie;
|
|
90
|
+
}
|
|
91
|
+
proxyRequest.setHeader("cookie", cookies);
|
|
92
|
+
if (process.env.PROXY_AS_GUEST !== "true") {
|
|
93
|
+
const reqUrl = new URL(incomingRequest.url || "", `http://${incomingRequest.headers.host}`);
|
|
94
|
+
if (reqUrl.searchParams.get("asGuest") === "true") {
|
|
95
|
+
reqUrl.searchParams.set("asGuest", "false");
|
|
96
|
+
proxyRequest.path = reqUrl.pathname + reqUrl.search;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
83
100
|
}
|
|
84
101
|
}));
|
|
85
102
|
}
|
package/build/es/middleware.js
CHANGED
|
@@ -77,6 +77,32 @@ export function addRemoteProxyMiddleware(app, proxyConfig) {
|
|
|
77
77
|
// Preserve the original path, including double slashes
|
|
78
78
|
const originalPath = incomingRequest.url;
|
|
79
79
|
proxyRequest.path = originalPath;
|
|
80
|
+
// Add auth token in cookies
|
|
81
|
+
// Retrieve the current cookie header
|
|
82
|
+
if (process.env.AUTH_TOKEN) {
|
|
83
|
+
let cookies = proxyRequest.getHeader('cookie') || '';
|
|
84
|
+
// Append the SID token to the cookies
|
|
85
|
+
const sidCookie = `__Secure-has-sid=1; sid=${process.env.AUTH_TOKEN};`;
|
|
86
|
+
if (cookies) {
|
|
87
|
+
cookies += `; ${sidCookie}`;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
cookies = sidCookie;
|
|
91
|
+
}
|
|
92
|
+
// Set our auth cookies on the proxied request
|
|
93
|
+
proxyRequest.setHeader('cookie', cookies);
|
|
94
|
+
// TODO once local-dev bundles are updated appropriately we can remove this
|
|
95
|
+
// Remove asGuest from query parameters as that can cause issues with certain requests
|
|
96
|
+
// Example Request for CMS image that fails with asGuest=true
|
|
97
|
+
// /services/data/v62.0/connect/sites/0DMSB000000jBc24AE/cms/delivery/contents?includeContentBody=true&contentKeys=MCB6JD6GWNRVFYHN2CAP5WQNOXQE&language=en-US&asGuest=true&htmlEncode=false
|
|
98
|
+
if (process.env.PROXY_AS_GUEST !== 'true') {
|
|
99
|
+
const reqUrl = new URL(incomingRequest.url || '', `http://${incomingRequest.headers.host}`);
|
|
100
|
+
if (reqUrl.searchParams.get('asGuest') === 'true') {
|
|
101
|
+
reqUrl.searchParams.set('asGuest', 'false');
|
|
102
|
+
proxyRequest.path = reqUrl.pathname + reqUrl.search;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
80
106
|
},
|
|
81
107
|
}));
|
|
82
108
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.15.0-alpha.
|
|
7
|
+
"version": "0.15.0-alpha.40",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
"build": "tsc -b"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@lwrjs/diagnostics": "0.15.0-alpha.
|
|
37
|
-
"@lwrjs/shared-utils": "0.15.0-alpha.
|
|
36
|
+
"@lwrjs/diagnostics": "0.15.0-alpha.40",
|
|
37
|
+
"@lwrjs/shared-utils": "0.15.0-alpha.40",
|
|
38
38
|
"express": "^4.20.0",
|
|
39
39
|
"http-proxy-middleware": "2.0.7"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@lwrjs/types": "0.15.0-alpha.
|
|
42
|
+
"@lwrjs/types": "0.15.0-alpha.40"
|
|
43
43
|
},
|
|
44
44
|
"engines": {
|
|
45
45
|
"node": ">=18.0.0"
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"volta": {
|
|
48
48
|
"extends": "../../../package.json"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "327c965daff99a942bdf9f855f165febebd1835f"
|
|
51
51
|
}
|