@lwrjs/server 0.11.0-alpha.9 → 0.11.1
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.
|
@@ -10,6 +10,18 @@ __markAsModule(exports);
|
|
|
10
10
|
__export(exports, {
|
|
11
11
|
AbstractMiddlewareRequest: () => AbstractMiddlewareRequest
|
|
12
12
|
});
|
|
13
|
+
function parseForwardedHeader(forwarded) {
|
|
14
|
+
if (!forwarded)
|
|
15
|
+
return void 0;
|
|
16
|
+
const couples = forwarded.toLocaleLowerCase().split(";");
|
|
17
|
+
const map = couples.reduce((m, c) => {
|
|
18
|
+
const [key, value] = c.trim().split("=");
|
|
19
|
+
m[key] = value;
|
|
20
|
+
return m;
|
|
21
|
+
}, {});
|
|
22
|
+
const proto = map.proto ? `${map.proto}://` : "";
|
|
23
|
+
return map.host ? `${proto}${map.host}` : void 0;
|
|
24
|
+
}
|
|
13
25
|
var AbstractMiddlewareRequest = class {
|
|
14
26
|
constructor(isSiteGenerationRequest) {
|
|
15
27
|
this.isSiteGenerationRequest = isSiteGenerationRequest || false;
|
|
@@ -43,7 +55,15 @@ var AbstractMiddlewareRequest = class {
|
|
|
43
55
|
return !targetEnvironment || targetEnvironment === defaultEnvironment || supportedEnvironments?.includes(targetEnvironment);
|
|
44
56
|
}
|
|
45
57
|
getRuntimeContext(defaultRuntimeEnvironment) {
|
|
46
|
-
const {
|
|
58
|
+
const {
|
|
59
|
+
format,
|
|
60
|
+
apiVersion,
|
|
61
|
+
basePath: basePathParam,
|
|
62
|
+
compat,
|
|
63
|
+
locale: localeParam,
|
|
64
|
+
environment,
|
|
65
|
+
bundleSpecifier
|
|
66
|
+
} = this.params;
|
|
47
67
|
const debug = this.query.debug !== void 0;
|
|
48
68
|
const bundle = !!bundleSpecifier;
|
|
49
69
|
const runtimeEnvironment = {
|
|
@@ -53,12 +73,24 @@ var AbstractMiddlewareRequest = class {
|
|
|
53
73
|
debug: debug || defaultRuntimeEnvironment.debug,
|
|
54
74
|
apiVersion: apiVersion || defaultRuntimeEnvironment.apiVersion,
|
|
55
75
|
bundle: bundle || defaultRuntimeEnvironment.bundle,
|
|
56
|
-
basePath: this.basePath ||
|
|
76
|
+
basePath: this.basePath || basePathParam || defaultRuntimeEnvironment.basePath
|
|
57
77
|
};
|
|
78
|
+
let host = parseForwardedHeader(this.headers?.forwarded) || this.headers?.host || void 0;
|
|
79
|
+
if (host && !host.startsWith("http")) {
|
|
80
|
+
host = `${this.protocol}://${host}`;
|
|
81
|
+
}
|
|
82
|
+
const basePath = runtimeEnvironment.basePath;
|
|
83
|
+
const defaultLocale = runtimeEnvironment.i18n.defaultLocale;
|
|
84
|
+
const locale = localeParam || this.locale || defaultLocale;
|
|
85
|
+
const uiBasePath = runtimeEnvironment.i18n.uriPattern === "path-prefix" && defaultLocale !== locale ? `${basePath}/${locale}` : `${basePath}`;
|
|
86
|
+
const assetBasePath = `${runtimeEnvironment.basePath}${runtimeEnvironment.defaultAssetPath}`;
|
|
58
87
|
const runtimeParams = {
|
|
59
|
-
basePath
|
|
60
|
-
locale
|
|
61
|
-
|
|
88
|
+
basePath,
|
|
89
|
+
locale,
|
|
90
|
+
assetBasePath,
|
|
91
|
+
uiBasePath,
|
|
92
|
+
environment,
|
|
93
|
+
host
|
|
62
94
|
};
|
|
63
95
|
return {
|
|
64
96
|
runtimeEnvironment,
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
// See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded
|
|
2
|
+
function parseForwardedHeader(forwarded) {
|
|
3
|
+
if (!forwarded)
|
|
4
|
+
return undefined;
|
|
5
|
+
// parse the Forwarded header to find the "host" and "proto"
|
|
6
|
+
// case-insensitive and can contain empty space around the key=value pairs
|
|
7
|
+
const couples = forwarded.toLocaleLowerCase().split(';');
|
|
8
|
+
const map = couples.reduce((m, c) => {
|
|
9
|
+
const [key, value] = c.trim().split('=');
|
|
10
|
+
m[key] = value;
|
|
11
|
+
return m;
|
|
12
|
+
}, {});
|
|
13
|
+
// build the protocol:host string
|
|
14
|
+
const proto = map.proto ? `${map.proto}://` : '';
|
|
15
|
+
return map.host ? `${proto}${map.host}` : undefined;
|
|
16
|
+
}
|
|
1
17
|
export class AbstractMiddlewareRequest {
|
|
2
18
|
constructor(isSiteGenerationRequest) {
|
|
3
19
|
this.isSiteGenerationRequest = isSiteGenerationRequest || false;
|
|
@@ -36,7 +52,7 @@ export class AbstractMiddlewareRequest {
|
|
|
36
52
|
supportedEnvironments?.includes(targetEnvironment));
|
|
37
53
|
}
|
|
38
54
|
getRuntimeContext(defaultRuntimeEnvironment) {
|
|
39
|
-
const { format, apiVersion, basePath, compat, locale, environment, bundleSpecifier } = this.params;
|
|
55
|
+
const { format, apiVersion, basePath: basePathParam, compat, locale: localeParam, environment, bundleSpecifier, } = this.params;
|
|
40
56
|
const debug = this.query.debug !== undefined;
|
|
41
57
|
const bundle = !!bundleSpecifier;
|
|
42
58
|
const runtimeEnvironment = {
|
|
@@ -47,12 +63,29 @@ export class AbstractMiddlewareRequest {
|
|
|
47
63
|
debug: debug || defaultRuntimeEnvironment.debug,
|
|
48
64
|
apiVersion: apiVersion || defaultRuntimeEnvironment.apiVersion,
|
|
49
65
|
bundle: bundle || defaultRuntimeEnvironment.bundle,
|
|
50
|
-
basePath: this.basePath ||
|
|
66
|
+
basePath: this.basePath || basePathParam || defaultRuntimeEnvironment.basePath,
|
|
51
67
|
};
|
|
68
|
+
let host = parseForwardedHeader(this.headers?.forwarded) || this.headers?.host || undefined;
|
|
69
|
+
if (host && !host.startsWith('http')) {
|
|
70
|
+
host = `${this.protocol}://${host}`;
|
|
71
|
+
}
|
|
72
|
+
const basePath = runtimeEnvironment.basePath;
|
|
73
|
+
const defaultLocale = runtimeEnvironment.i18n.defaultLocale;
|
|
74
|
+
const locale = localeParam || this.locale || defaultLocale;
|
|
75
|
+
// Base path to be used in routing ${basePath}/locale
|
|
76
|
+
const uiBasePath = runtimeEnvironment.i18n.uriPattern === 'path-prefix' && defaultLocale !== locale
|
|
77
|
+
? `${basePath}/${locale}`
|
|
78
|
+
: `${basePath}`;
|
|
79
|
+
// Path to static artifacts on MRT the is ${basePath}/mobify/build/${bundleId}
|
|
80
|
+
// On express this is ${basePath}
|
|
81
|
+
const assetBasePath = `${runtimeEnvironment.basePath}${runtimeEnvironment.defaultAssetPath}`;
|
|
52
82
|
const runtimeParams = {
|
|
53
|
-
basePath
|
|
54
|
-
locale
|
|
83
|
+
basePath,
|
|
84
|
+
locale,
|
|
85
|
+
assetBasePath,
|
|
86
|
+
uiBasePath,
|
|
55
87
|
environment,
|
|
88
|
+
host,
|
|
56
89
|
};
|
|
57
90
|
return {
|
|
58
91
|
runtimeEnvironment,
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.11.
|
|
7
|
+
"version": "0.11.1",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"build/**/*.d.ts"
|
|
35
35
|
],
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@lwrjs/types": "0.11.
|
|
37
|
+
"@lwrjs/types": "0.11.1",
|
|
38
38
|
"@types/koa-compress": "^4.0.1",
|
|
39
39
|
"@types/koa__router": "^8.0.4",
|
|
40
40
|
"jest-express": "^1.12.0"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@koa/router": "^10.0.0",
|
|
44
|
-
"@lwrjs/shared-utils": "0.11.
|
|
44
|
+
"@lwrjs/shared-utils": "0.11.1",
|
|
45
45
|
"@types/express": "^4.17.17",
|
|
46
46
|
"@types/koa": "^2.11.7",
|
|
47
47
|
"express": "^4.18.2",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"engines": {
|
|
52
52
|
"node": ">=16.0.0"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "b7c40fdcd86635dd4e368c0a2e91c5d3374c0fcf"
|
|
55
55
|
}
|