@lwrjs/core 0.15.0-alpha.35 → 0.15.0-alpha.37
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/context/provider.cjs +2 -4
- package/build/cjs/middleware/utils/compression.cjs +16 -0
- package/build/cjs/middleware/view-middleware.cjs +29 -1
- package/build/es/context/provider.js +1 -2
- package/build/es/middleware/utils/compression.d.ts +2 -0
- package/build/es/middleware/utils/compression.js +6 -0
- package/build/es/middleware/view-middleware.js +35 -2
- package/package.json +31 -31
|
@@ -46,8 +46,7 @@ function createProviderContext(serverContext) {
|
|
|
46
46
|
environment,
|
|
47
47
|
basePath,
|
|
48
48
|
bundleConfig,
|
|
49
|
-
staticSiteGenerator
|
|
50
|
-
_isSsrCompilerEnabled
|
|
49
|
+
staticSiteGenerator
|
|
51
50
|
} = serverContext.appConfig;
|
|
52
51
|
const {onModuleDefinitionChange, onModuleSourceChange} = serverContext.appObserver;
|
|
53
52
|
const {
|
|
@@ -85,8 +84,7 @@ function createProviderContext(serverContext) {
|
|
|
85
84
|
amdLoader,
|
|
86
85
|
esmLoader,
|
|
87
86
|
environment,
|
|
88
|
-
bundleConfig
|
|
89
|
-
_isSsrCompilerEnabled
|
|
87
|
+
bundleConfig
|
|
90
88
|
}),
|
|
91
89
|
runtimeEnvironment: (0, import_shared_utils.deepFreeze)(serverContext.runtimeEnvironment),
|
|
92
90
|
watcherFactory: serverContext.watcherFactory,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// packages/@lwrjs/core/src/middleware/utils/compression.ts
|
|
9
|
+
__markAsModule(exports);
|
|
10
|
+
__export(exports, {
|
|
11
|
+
getMrtCompressionThreshold: () => getMrtCompressionThreshold
|
|
12
|
+
});
|
|
13
|
+
var MAX_LAMBDA_RESPONSE_SIZE = 6 * 1024 * 1024;
|
|
14
|
+
function getMrtCompressionThreshold() {
|
|
15
|
+
return MAX_LAMBDA_RESPONSE_SIZE - 5 * 1024 * 1024;
|
|
16
|
+
}
|
|
@@ -35,10 +35,13 @@ var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
|
|
|
35
35
|
var import_error_handling = __toModule(require("./utils/error-handling.cjs"));
|
|
36
36
|
var import_view_registry = __toModule(require("@lwrjs/view-registry"));
|
|
37
37
|
var import_instrumentation2 = __toModule(require("@lwrjs/instrumentation"));
|
|
38
|
+
var import_zlib = __toModule(require("zlib"));
|
|
39
|
+
var import_compression = __toModule(require("./utils/compression.cjs"));
|
|
38
40
|
function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
39
41
|
const errorRoute = errorRoutes.find((route2) => route2.status === 500);
|
|
40
42
|
const appConfig = context.appConfig;
|
|
41
43
|
const {environment: environmentConfig} = appConfig;
|
|
44
|
+
const mrtCompressionThreshold = (0, import_compression.getMrtCompressionThreshold)();
|
|
42
45
|
return async (req, res) => {
|
|
43
46
|
if (!req.validateEnvironmentRequest(appConfig)) {
|
|
44
47
|
res.status(400);
|
|
@@ -144,7 +147,32 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
|
144
147
|
}
|
|
145
148
|
}
|
|
146
149
|
res.status(status);
|
|
147
|
-
|
|
150
|
+
const viewResponseBody = viewResponse.body;
|
|
151
|
+
let shouldCompress, viewResponseSize;
|
|
152
|
+
if ((0, import_shared_utils.isLambdaEnv)() && typeof viewResponseBody === "string") {
|
|
153
|
+
viewResponseSize = Buffer.byteLength(viewResponseBody, "utf-8");
|
|
154
|
+
shouldCompress = Buffer.byteLength(viewResponseBody, "utf-8") >= mrtCompressionThreshold;
|
|
155
|
+
}
|
|
156
|
+
if (shouldCompress) {
|
|
157
|
+
const start = performance.now();
|
|
158
|
+
let compressionMethod;
|
|
159
|
+
if (req.headers["accept-encoding"]?.includes("br")) {
|
|
160
|
+
res.setHeader("Content-Encoding", "br");
|
|
161
|
+
compressionMethod = import_zlib.brotliCompressSync;
|
|
162
|
+
} else if (req.headers["accept-encoding"]?.includes("gzip")) {
|
|
163
|
+
compressionMethod = import_zlib.gzipSync;
|
|
164
|
+
res.setHeader("Content-Encoding", "gzip");
|
|
165
|
+
} else {
|
|
166
|
+
import_diagnostics.logger.warn(`View size (${viewResponseSize}) should be compressed, but failed due to missing content-encoding headers.`);
|
|
167
|
+
return res.send(viewResponse.body);
|
|
168
|
+
}
|
|
169
|
+
const compressedView = compressionMethod(viewResponseBody);
|
|
170
|
+
const end = performance.now();
|
|
171
|
+
import_diagnostics.logger.warn(`View size (${viewResponseSize}) compressed due to Lambda response limit. Compression took ${Math.round(end - start)} ms`);
|
|
172
|
+
res.send(compressedView);
|
|
173
|
+
} else {
|
|
174
|
+
res.send(viewResponse.body);
|
|
175
|
+
}
|
|
148
176
|
};
|
|
149
177
|
}
|
|
150
178
|
function createConfigMiddleware(routes, context, viewHandler) {
|
|
@@ -3,7 +3,7 @@ import { deepFreeze } from '@lwrjs/shared-utils';
|
|
|
3
3
|
import { SiteMetadataImpl } from '@lwrjs/static/site-metadata';
|
|
4
4
|
export function createProviderContext(serverContext) {
|
|
5
5
|
// This is a subset of config to user-land code
|
|
6
|
-
const { assets, cacheDir, i18n, lwc: { modules = [] }, routes, errorRoutes, rootDir, contentDir, layoutsDir, locker, amdLoader, esmLoader, environment, basePath, bundleConfig, staticSiteGenerator,
|
|
6
|
+
const { assets, cacheDir, i18n, lwc: { modules = [] }, routes, errorRoutes, rootDir, contentDir, layoutsDir, locker, amdLoader, esmLoader, environment, basePath, bundleConfig, staticSiteGenerator, } = serverContext.appConfig;
|
|
7
7
|
const { onModuleDefinitionChange, onModuleSourceChange } = serverContext.appObserver;
|
|
8
8
|
const { notifyModuleDefinitionChanged, notifyModuleSourceChanged, notifyViewSourceChanged, notifyAssetSourceChanged, } = serverContext.appEmitter;
|
|
9
9
|
const siteMetadata = staticSiteGenerator.outputDir && fs.existsSync(staticSiteGenerator.outputDir)
|
|
@@ -38,7 +38,6 @@ export function createProviderContext(serverContext) {
|
|
|
38
38
|
esmLoader,
|
|
39
39
|
environment,
|
|
40
40
|
bundleConfig,
|
|
41
|
-
_isSsrCompilerEnabled,
|
|
42
41
|
}),
|
|
43
42
|
runtimeEnvironment: deepFreeze(serverContext.runtimeEnvironment),
|
|
44
43
|
watcherFactory: serverContext.watcherFactory,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// currently documented AWS Lambda limit, 6MB
|
|
2
|
+
const MAX_LAMBDA_RESPONSE_SIZE = 6 * 1024 * 1024;
|
|
3
|
+
export function getMrtCompressionThreshold() {
|
|
4
|
+
return MAX_LAMBDA_RESPONSE_SIZE - 5 * 1024 * 1024; // Trigger compression within 1MB of limit
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=compression.js.map
|
|
@@ -2,15 +2,18 @@ import { TextEncoder } from 'util';
|
|
|
2
2
|
import { URLSearchParams } from 'url';
|
|
3
3
|
import { descriptions, logger } from '@lwrjs/diagnostics';
|
|
4
4
|
import { getClientRoutes } from '@lwrjs/router';
|
|
5
|
-
import { decodeViewPath, extractRequestParams, getClientBootstrapConfigurationRoutes, isURL, parseRequestDepth, REQUEST_DEPTH_KEY, shortestTtl, } from '@lwrjs/shared-utils';
|
|
5
|
+
import { decodeViewPath, extractRequestParams, getClientBootstrapConfigurationRoutes, isURL, parseRequestDepth, REQUEST_DEPTH_KEY, shortestTtl, isLambdaEnv, } from '@lwrjs/shared-utils';
|
|
6
6
|
import { RequestHandlerSpan, getTracer } from '@lwrjs/instrumentation';
|
|
7
7
|
import { handleErrors } from './utils/error-handling.js';
|
|
8
8
|
import { LwrViewHandler } from '@lwrjs/view-registry';
|
|
9
9
|
import { getTraceCollector } from '@lwrjs/instrumentation';
|
|
10
|
+
import { brotliCompressSync, gzipSync } from 'zlib';
|
|
11
|
+
import { getMrtCompressionThreshold } from './utils/compression.js';
|
|
10
12
|
function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
11
13
|
const errorRoute = errorRoutes.find((route) => route.status === 500);
|
|
12
14
|
const appConfig = context.appConfig;
|
|
13
15
|
const { environment: environmentConfig } = appConfig;
|
|
16
|
+
const mrtCompressionThreshold = getMrtCompressionThreshold();
|
|
14
17
|
return async (req, res) => {
|
|
15
18
|
if (!req.validateEnvironmentRequest(appConfig)) {
|
|
16
19
|
res.status(400);
|
|
@@ -128,7 +131,37 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
|
128
131
|
}
|
|
129
132
|
}
|
|
130
133
|
res.status(status);
|
|
131
|
-
|
|
134
|
+
// LWR@MRT 254 temporary safeguard for "dupe styles" issue causing huge base docs
|
|
135
|
+
const viewResponseBody = viewResponse.body;
|
|
136
|
+
let shouldCompress, viewResponseSize;
|
|
137
|
+
if (isLambdaEnv() && typeof viewResponseBody === 'string') {
|
|
138
|
+
viewResponseSize = Buffer.byteLength(viewResponseBody, 'utf-8');
|
|
139
|
+
shouldCompress = Buffer.byteLength(viewResponseBody, 'utf-8') >= mrtCompressionThreshold;
|
|
140
|
+
}
|
|
141
|
+
// Conditionally apply compression if size is near the threshold
|
|
142
|
+
if (shouldCompress) {
|
|
143
|
+
const start = performance.now();
|
|
144
|
+
let compressionMethod;
|
|
145
|
+
if (req.headers['accept-encoding']?.includes('br')) {
|
|
146
|
+
res.setHeader('Content-Encoding', 'br');
|
|
147
|
+
compressionMethod = brotliCompressSync;
|
|
148
|
+
}
|
|
149
|
+
else if (req.headers['accept-encoding']?.includes('gzip')) {
|
|
150
|
+
compressionMethod = gzipSync;
|
|
151
|
+
res.setHeader('Content-Encoding', 'gzip');
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
logger.warn(`View size (${viewResponseSize}) should be compressed, but failed due to missing content-encoding headers.`);
|
|
155
|
+
return res.send(viewResponse.body);
|
|
156
|
+
}
|
|
157
|
+
const compressedView = compressionMethod(viewResponseBody);
|
|
158
|
+
const end = performance.now();
|
|
159
|
+
logger.warn(`View size (${viewResponseSize}) compressed due to Lambda response limit. Compression took ${Math.round(end - start)} ms`);
|
|
160
|
+
res.send(compressedView);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
res.send(viewResponse.body);
|
|
164
|
+
}
|
|
132
165
|
};
|
|
133
166
|
}
|
|
134
167
|
function createConfigMiddleware(routes, context, viewHandler) {
|
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.37",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -43,34 +43,34 @@
|
|
|
43
43
|
"build": "tsc -b"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@lwrjs/app-service": "0.15.0-alpha.
|
|
47
|
-
"@lwrjs/asset-registry": "0.15.0-alpha.
|
|
48
|
-
"@lwrjs/asset-transformer": "0.15.0-alpha.
|
|
49
|
-
"@lwrjs/base-view-provider": "0.15.0-alpha.
|
|
50
|
-
"@lwrjs/base-view-transformer": "0.15.0-alpha.
|
|
51
|
-
"@lwrjs/client-modules": "0.15.0-alpha.
|
|
52
|
-
"@lwrjs/config": "0.15.0-alpha.
|
|
53
|
-
"@lwrjs/diagnostics": "0.15.0-alpha.
|
|
54
|
-
"@lwrjs/esbuild": "0.15.0-alpha.
|
|
55
|
-
"@lwrjs/fs-asset-provider": "0.15.0-alpha.
|
|
56
|
-
"@lwrjs/fs-watch": "0.15.0-alpha.
|
|
57
|
-
"@lwrjs/html-view-provider": "0.15.0-alpha.
|
|
58
|
-
"@lwrjs/instrumentation": "0.15.0-alpha.
|
|
59
|
-
"@lwrjs/loader": "0.15.0-alpha.
|
|
60
|
-
"@lwrjs/lwc-module-provider": "0.15.0-alpha.
|
|
61
|
-
"@lwrjs/lwc-ssr": "0.15.0-alpha.
|
|
62
|
-
"@lwrjs/markdown-view-provider": "0.15.0-alpha.
|
|
63
|
-
"@lwrjs/module-bundler": "0.15.0-alpha.
|
|
64
|
-
"@lwrjs/module-registry": "0.15.0-alpha.
|
|
65
|
-
"@lwrjs/npm-module-provider": "0.15.0-alpha.
|
|
66
|
-
"@lwrjs/nunjucks-view-provider": "0.15.0-alpha.
|
|
67
|
-
"@lwrjs/o11y": "0.15.0-alpha.
|
|
68
|
-
"@lwrjs/resource-registry": "0.15.0-alpha.
|
|
69
|
-
"@lwrjs/router": "0.15.0-alpha.
|
|
70
|
-
"@lwrjs/server": "0.15.0-alpha.
|
|
71
|
-
"@lwrjs/shared-utils": "0.15.0-alpha.
|
|
72
|
-
"@lwrjs/static": "0.15.0-alpha.
|
|
73
|
-
"@lwrjs/view-registry": "0.15.0-alpha.
|
|
46
|
+
"@lwrjs/app-service": "0.15.0-alpha.37",
|
|
47
|
+
"@lwrjs/asset-registry": "0.15.0-alpha.37",
|
|
48
|
+
"@lwrjs/asset-transformer": "0.15.0-alpha.37",
|
|
49
|
+
"@lwrjs/base-view-provider": "0.15.0-alpha.37",
|
|
50
|
+
"@lwrjs/base-view-transformer": "0.15.0-alpha.37",
|
|
51
|
+
"@lwrjs/client-modules": "0.15.0-alpha.37",
|
|
52
|
+
"@lwrjs/config": "0.15.0-alpha.37",
|
|
53
|
+
"@lwrjs/diagnostics": "0.15.0-alpha.37",
|
|
54
|
+
"@lwrjs/esbuild": "0.15.0-alpha.37",
|
|
55
|
+
"@lwrjs/fs-asset-provider": "0.15.0-alpha.37",
|
|
56
|
+
"@lwrjs/fs-watch": "0.15.0-alpha.37",
|
|
57
|
+
"@lwrjs/html-view-provider": "0.15.0-alpha.37",
|
|
58
|
+
"@lwrjs/instrumentation": "0.15.0-alpha.37",
|
|
59
|
+
"@lwrjs/loader": "0.15.0-alpha.37",
|
|
60
|
+
"@lwrjs/lwc-module-provider": "0.15.0-alpha.37",
|
|
61
|
+
"@lwrjs/lwc-ssr": "0.15.0-alpha.37",
|
|
62
|
+
"@lwrjs/markdown-view-provider": "0.15.0-alpha.37",
|
|
63
|
+
"@lwrjs/module-bundler": "0.15.0-alpha.37",
|
|
64
|
+
"@lwrjs/module-registry": "0.15.0-alpha.37",
|
|
65
|
+
"@lwrjs/npm-module-provider": "0.15.0-alpha.37",
|
|
66
|
+
"@lwrjs/nunjucks-view-provider": "0.15.0-alpha.37",
|
|
67
|
+
"@lwrjs/o11y": "0.15.0-alpha.37",
|
|
68
|
+
"@lwrjs/resource-registry": "0.15.0-alpha.37",
|
|
69
|
+
"@lwrjs/router": "0.15.0-alpha.37",
|
|
70
|
+
"@lwrjs/server": "0.15.0-alpha.37",
|
|
71
|
+
"@lwrjs/shared-utils": "0.15.0-alpha.37",
|
|
72
|
+
"@lwrjs/static": "0.15.0-alpha.37",
|
|
73
|
+
"@lwrjs/view-registry": "0.15.0-alpha.37",
|
|
74
74
|
"chokidar": "^3.6.0",
|
|
75
75
|
"esbuild": "^0.9.7",
|
|
76
76
|
"fs-extra": "^11.2.0",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"ws": "^8.18.0"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
|
-
"@lwrjs/types": "0.15.0-alpha.
|
|
83
|
+
"@lwrjs/types": "0.15.0-alpha.37",
|
|
84
84
|
"@types/ws": "^8.5.12",
|
|
85
85
|
"memfs": "^4.13.0"
|
|
86
86
|
},
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"volta": {
|
|
94
94
|
"extends": "../../../package.json"
|
|
95
95
|
},
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "1211275df818eb68a933ea744c13c9f1a525bcd6"
|
|
97
97
|
}
|