@lwrjs/dev-proxy-server 0.15.0-alpha.39 → 0.15.0-alpha.41

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.
@@ -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
  }
@@ -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.39",
7
+ "version": "0.15.0-alpha.41",
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.39",
37
- "@lwrjs/shared-utils": "0.15.0-alpha.39",
36
+ "@lwrjs/diagnostics": "0.15.0-alpha.41",
37
+ "@lwrjs/shared-utils": "0.15.0-alpha.41",
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.39"
42
+ "@lwrjs/types": "0.15.0-alpha.41"
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": "27d047854320831ffa9aa6137e2f40691c896448"
50
+ "gitHead": "26a304d3a5f92daf1d3eff3d9c937eccf1372fd3"
51
51
  }