@lwrjs/dev-proxy-server 0.15.0 → 0.15.2
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 +14 -8
- package/build/es/middleware.js +18 -11
- package/package.json +5 -5
package/build/cjs/middleware.cjs
CHANGED
|
@@ -55,6 +55,9 @@ function addLocalProxyMiddleware(app, defaultHost, remoteOrigin) {
|
|
|
55
55
|
proxyRequest.setHeader(HOST, domainAndPort);
|
|
56
56
|
const forwarded = incomingRequest.headers.forwarded;
|
|
57
57
|
proxyRequest.setHeader("Forwarded", forwarded ? forwarded : getForwardedHeader(incomingRequest, remoteOrigin));
|
|
58
|
+
if (process.env.AUTH_TOKEN && !proxyRequest.path.startsWith("/mobify/bundle/")) {
|
|
59
|
+
addAuthCookie(proxyRequest, process.env.AUTH_TOKEN);
|
|
60
|
+
}
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
}));
|
|
@@ -86,14 +89,7 @@ function addRemoteProxyMiddleware(app, proxyConfig) {
|
|
|
86
89
|
const originalPath = incomingRequest.url;
|
|
87
90
|
proxyRequest.path = originalPath;
|
|
88
91
|
if (process.env.AUTH_TOKEN) {
|
|
89
|
-
|
|
90
|
-
const sidCookie = `__Secure-has-sid=1; sid=${process.env.AUTH_TOKEN};`;
|
|
91
|
-
if (cookies) {
|
|
92
|
-
cookies += `; ${sidCookie}`;
|
|
93
|
-
} else {
|
|
94
|
-
cookies = sidCookie;
|
|
95
|
-
}
|
|
96
|
-
proxyRequest.setHeader("cookie", cookies);
|
|
92
|
+
addAuthCookie(proxyRequest, process.env.AUTH_TOKEN);
|
|
97
93
|
if (process.env.PROXY_AS_GUEST !== "true") {
|
|
98
94
|
const reqUrl = new URL(incomingRequest.url || "", `http://${incomingRequest.headers.host}`);
|
|
99
95
|
if (reqUrl.searchParams.get("asGuest") === "true") {
|
|
@@ -117,3 +113,13 @@ function resolveLogLevel(currentLevel) {
|
|
|
117
113
|
return ProxyLogLevels.Error;
|
|
118
114
|
return ProxyLogLevels.Silent;
|
|
119
115
|
}
|
|
116
|
+
function addAuthCookie(req, authToken) {
|
|
117
|
+
let cookies = req.getHeader("cookie") || "";
|
|
118
|
+
const sidCookie = `__Secure-has-sid=1; sid=${authToken};`;
|
|
119
|
+
if (cookies) {
|
|
120
|
+
cookies += `; ${sidCookie}`;
|
|
121
|
+
} else {
|
|
122
|
+
cookies = sidCookie;
|
|
123
|
+
}
|
|
124
|
+
req.setHeader("cookie", cookies);
|
|
125
|
+
}
|
package/build/es/middleware.js
CHANGED
|
@@ -36,6 +36,10 @@ export function addLocalProxyMiddleware(app, defaultHost, remoteOrigin) {
|
|
|
36
36
|
// Set the Forwarded header if it's not defined
|
|
37
37
|
const forwarded = incomingRequest.headers.forwarded;
|
|
38
38
|
proxyRequest.setHeader('Forwarded', forwarded ? forwarded : getForwardedHeader(incomingRequest, remoteOrigin));
|
|
39
|
+
// Add auth token to cookies; used in the fetchController during local preview
|
|
40
|
+
if (process.env.AUTH_TOKEN && !proxyRequest.path.startsWith('/mobify/bundle/')) {
|
|
41
|
+
addAuthCookie(proxyRequest, process.env.AUTH_TOKEN);
|
|
42
|
+
}
|
|
39
43
|
}
|
|
40
44
|
},
|
|
41
45
|
}));
|
|
@@ -85,17 +89,7 @@ export function addRemoteProxyMiddleware(app, proxyConfig) {
|
|
|
85
89
|
// Add auth token in cookies
|
|
86
90
|
// Retrieve the current cookie header
|
|
87
91
|
if (process.env.AUTH_TOKEN) {
|
|
88
|
-
|
|
89
|
-
// Append the SID token to the cookies
|
|
90
|
-
const sidCookie = `__Secure-has-sid=1; sid=${process.env.AUTH_TOKEN};`;
|
|
91
|
-
if (cookies) {
|
|
92
|
-
cookies += `; ${sidCookie}`;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
cookies = sidCookie;
|
|
96
|
-
}
|
|
97
|
-
// Set our auth cookies on the proxied request
|
|
98
|
-
proxyRequest.setHeader('cookie', cookies);
|
|
92
|
+
addAuthCookie(proxyRequest, process.env.AUTH_TOKEN);
|
|
99
93
|
// TODO once local-dev bundles are updated appropriately we can remove this
|
|
100
94
|
// Remove asGuest from query parameters as that can cause issues with certain requests
|
|
101
95
|
// Example Request for CMS image that fails with asGuest=true
|
|
@@ -125,4 +119,17 @@ function resolveLogLevel(currentLevel) {
|
|
|
125
119
|
// default log level
|
|
126
120
|
return ProxyLogLevels.Silent;
|
|
127
121
|
}
|
|
122
|
+
function addAuthCookie(req, authToken) {
|
|
123
|
+
let cookies = req.getHeader('cookie') || '';
|
|
124
|
+
// Append the SID token to the cookies
|
|
125
|
+
const sidCookie = `__Secure-has-sid=1; sid=${authToken};`;
|
|
126
|
+
if (cookies) {
|
|
127
|
+
cookies += `; ${sidCookie}`;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
cookies = sidCookie;
|
|
131
|
+
}
|
|
132
|
+
// Set our auth cookies on the proxied request
|
|
133
|
+
req.setHeader('cookie', cookies);
|
|
134
|
+
}
|
|
128
135
|
//# sourceMappingURL=middleware.js.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.15.
|
|
7
|
+
"version": "0.15.2",
|
|
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.
|
|
37
|
-
"@lwrjs/shared-utils": "0.15.
|
|
36
|
+
"@lwrjs/diagnostics": "0.15.2",
|
|
37
|
+
"@lwrjs/shared-utils": "0.15.2",
|
|
38
38
|
"express": "^4.20.0",
|
|
39
39
|
"http-proxy-middleware": "2.0.7"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@lwrjs/types": "0.15.
|
|
42
|
+
"@lwrjs/types": "0.15.2"
|
|
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": "8cbcb6a273286c213406b270d9e480d62c1ea917"
|
|
51
51
|
}
|