@lwrjs/core 0.15.0-alpha.16 → 0.15.0-alpha.18
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/__mocks__/undici.cjs +25 -0
- package/build/cjs/index.cjs +2 -2
- package/build/cjs/middleware/bundle-middleware.cjs +1 -1
- package/build/cjs/middleware/request-processor-middleware.cjs +10 -0
- package/build/cjs/middleware/view-middleware.cjs +24 -1
- package/build/es/index.js +2 -2
- package/build/es/middleware/bundle-middleware.js +3 -1
- package/build/es/middleware/request-processor-middleware.js +11 -0
- package/build/es/middleware/view-middleware.d.ts +1 -0
- package/build/es/middleware/view-middleware.js +22 -0
- package/package.json +32 -32
|
@@ -0,0 +1,25 @@
|
|
|
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/__mocks__/undici.ts
|
|
9
|
+
__markAsModule(exports);
|
|
10
|
+
__export(exports, {
|
|
11
|
+
Pool: () => Pool
|
|
12
|
+
});
|
|
13
|
+
var Pool = class {
|
|
14
|
+
async request() {
|
|
15
|
+
return Promise.resolve({
|
|
16
|
+
statusCode: 200,
|
|
17
|
+
body: {
|
|
18
|
+
text: () => Promise.resolve('{"one":1}'),
|
|
19
|
+
json: () => Promise.resolve({one: 1})
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
close() {
|
|
24
|
+
}
|
|
25
|
+
};
|
package/build/cjs/index.cjs
CHANGED
|
@@ -109,9 +109,9 @@ var LwrApp = class {
|
|
|
109
109
|
this.config = appConfig;
|
|
110
110
|
this.runtimeEnvironment = runtimeEnvironment;
|
|
111
111
|
this.globalData = globalData;
|
|
112
|
-
const {basePath, serverType} = this.config;
|
|
112
|
+
const {basePath, serverType, caseSensitiveRoutes} = this.config;
|
|
113
113
|
this.serverType = serverType;
|
|
114
|
-
this.app = (0, import_server.createInternalServer)(serverType, {basePath});
|
|
114
|
+
this.app = (0, import_server.createInternalServer)(serverType, {basePath, caseSensitiveRoutes});
|
|
115
115
|
this.server = this.app.createHttpServer();
|
|
116
116
|
this.use = this.app.use.bind(this.app);
|
|
117
117
|
this.all = this.app.all.bind(this.app);
|
|
@@ -84,7 +84,7 @@ function createBundleMiddleware(context) {
|
|
|
84
84
|
if (signature !== import_shared_utils.LATEST_SIGNATURE) {
|
|
85
85
|
res.setHeader("Cache-control", "public, max-age=31536000, immutable");
|
|
86
86
|
}
|
|
87
|
-
res.status(200).type("application/javascript").send(bundleDefinition.
|
|
87
|
+
res.status(200).type("application/javascript").send(await bundleDefinition.getCode());
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
function createSourceMapMiddleware(context) {
|
|
@@ -72,6 +72,16 @@ function requestProcessorMiddleware(app, context) {
|
|
|
72
72
|
});
|
|
73
73
|
const pathValue = parsedRequestClass?.basePath || basePath || "";
|
|
74
74
|
req.basePath = pathValue === "" || pathValue.indexOf("/") === 0 ? pathValue : `/${pathValue}`;
|
|
75
|
+
const expressRequest = req.req;
|
|
76
|
+
if (expressRequest?.url?.startsWith(parsedRequestClass?.basePath)) {
|
|
77
|
+
expressRequest.url = expressRequest.url.split(parsedRequestClass?.basePath)[1] || "/";
|
|
78
|
+
expressRequest.originalUrl = expressRequest.url.split(parsedRequestClass?.basePath)[1] || "/";
|
|
79
|
+
} else {
|
|
80
|
+
import_diagnostics.logger.warn({
|
|
81
|
+
label: `request-processor-middleware`,
|
|
82
|
+
message: `The URL requested for doesn't start with the Base path`
|
|
83
|
+
});
|
|
84
|
+
}
|
|
75
85
|
} else {
|
|
76
86
|
import_diagnostics.logger.debug({
|
|
77
87
|
label: `request-processor-middleware`,
|
|
@@ -24,6 +24,7 @@ var __toModule = (module2) => {
|
|
|
24
24
|
// packages/@lwrjs/core/src/middleware/view-middleware.ts
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
|
+
convertMetricsToArrayOfStrings: () => convertMetricsToArrayOfStrings,
|
|
27
28
|
viewMiddleware: () => viewMiddleware
|
|
28
29
|
});
|
|
29
30
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
@@ -32,6 +33,7 @@ var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
|
32
33
|
var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
|
|
33
34
|
var import_error_handling = __toModule(require("./utils/error-handling.cjs"));
|
|
34
35
|
var import_view_registry = __toModule(require("@lwrjs/view-registry"));
|
|
36
|
+
var import_aws_exporter = __toModule(require("@lwrjs/instrumentation/aws-exporter"));
|
|
35
37
|
function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
36
38
|
const errorRoute = errorRoutes.find((route2) => route2.status === 500);
|
|
37
39
|
const appConfig = context.appConfig;
|
|
@@ -62,12 +64,14 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
|
62
64
|
url: viewRequest.url,
|
|
63
65
|
params: viewRequest.params,
|
|
64
66
|
query: viewRequest.query,
|
|
65
|
-
cookie: req.headers?.cookie
|
|
67
|
+
cookie: req.headers?.cookie,
|
|
68
|
+
coreProxy: req.getCoreProxy(appConfig.coreProxy ?? void 0, route.bootstrap?.proxyForSSR)
|
|
66
69
|
};
|
|
67
70
|
const resolve = req.isJsonRequest() ? viewHandler.getViewJson : viewHandler.getViewContent;
|
|
68
71
|
let viewResponse;
|
|
69
72
|
let resolvedRoute;
|
|
70
73
|
let traceId;
|
|
74
|
+
let reqSpan;
|
|
71
75
|
try {
|
|
72
76
|
viewResponse = await (0, import_instrumentation.getTracer)().trace({
|
|
73
77
|
name: import_instrumentation.RequestHandlerSpan.GetView,
|
|
@@ -80,6 +84,7 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
|
80
84
|
}
|
|
81
85
|
}, (span) => {
|
|
82
86
|
traceId = span.traceId;
|
|
87
|
+
reqSpan = span.reqSpan;
|
|
83
88
|
return resolve.call(viewHandler, viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
84
89
|
});
|
|
85
90
|
resolvedRoute = route;
|
|
@@ -114,6 +119,11 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
|
114
119
|
}
|
|
115
120
|
if (traceId?.length) {
|
|
116
121
|
res.setHeader("x-trace-id", traceId);
|
|
122
|
+
if (reqSpan?.status?.code === 0) {
|
|
123
|
+
res.set({
|
|
124
|
+
"X-Custom-Lwr-Metric": convertMetricsToArrayOfStrings((0, import_aws_exporter.convertToReadableSpan)(reqSpan))
|
|
125
|
+
});
|
|
126
|
+
}
|
|
117
127
|
}
|
|
118
128
|
let status = resolvedRoute.status || viewResponse.status || 200;
|
|
119
129
|
const redirect = viewResponse.metadata?.viewDefinition?.redirect;
|
|
@@ -239,3 +249,16 @@ function addRedirectQueryParam(redirectUrl, depth) {
|
|
|
239
249
|
url.searchParams.set(import_shared_utils.REQUEST_DEPTH_KEY, String(depth + 1));
|
|
240
250
|
return url.toString().replace(fakeOrigin, "");
|
|
241
251
|
}
|
|
252
|
+
function convertMetricsToArrayOfStrings(span) {
|
|
253
|
+
const requiredMetrics = ["traceId", "name", "attributes", "duration"];
|
|
254
|
+
return requiredMetrics.reduce((metricString, prop) => {
|
|
255
|
+
if (metricString && !metricString.endsWith("; ")) {
|
|
256
|
+
metricString += "; ";
|
|
257
|
+
}
|
|
258
|
+
if (span[prop]) {
|
|
259
|
+
const propValue = typeof span[prop] === "object" ? JSON.stringify(span[prop]) : span[prop];
|
|
260
|
+
metricString += `${prop}: ${propValue}`;
|
|
261
|
+
}
|
|
262
|
+
return metricString;
|
|
263
|
+
}, "");
|
|
264
|
+
}
|
package/build/es/index.js
CHANGED
|
@@ -98,9 +98,9 @@ export class LwrApp {
|
|
|
98
98
|
this.config = appConfig;
|
|
99
99
|
this.runtimeEnvironment = runtimeEnvironment;
|
|
100
100
|
this.globalData = globalData;
|
|
101
|
-
const { basePath, serverType } = this.config;
|
|
101
|
+
const { basePath, serverType, caseSensitiveRoutes } = this.config;
|
|
102
102
|
this.serverType = serverType;
|
|
103
|
-
this.app = createInternalServer(serverType, { basePath });
|
|
103
|
+
this.app = createInternalServer(serverType, { basePath, caseSensitiveRoutes });
|
|
104
104
|
this.server = this.app.createHttpServer();
|
|
105
105
|
this.use = this.app.use.bind(this.app);
|
|
106
106
|
this.all = this.app.all.bind(this.app);
|
|
@@ -56,7 +56,9 @@ function createBundleMiddleware(context) {
|
|
|
56
56
|
if (signature !== LATEST_SIGNATURE) {
|
|
57
57
|
res.setHeader('Cache-control', 'public, max-age=31536000, immutable');
|
|
58
58
|
}
|
|
59
|
-
res.status(200)
|
|
59
|
+
res.status(200)
|
|
60
|
+
.type('application/javascript')
|
|
61
|
+
.send(await bundleDefinition.getCode());
|
|
60
62
|
};
|
|
61
63
|
}
|
|
62
64
|
function createSourceMapMiddleware(context) {
|
|
@@ -57,6 +57,17 @@ export function requestProcessorMiddleware(app, context) {
|
|
|
57
57
|
const pathValue = parsedRequestClass?.basePath || basePath || '';
|
|
58
58
|
// If base path is '' or starts with / leave it alone
|
|
59
59
|
req.basePath = pathValue === '' || pathValue.indexOf('/') === 0 ? pathValue : `/${pathValue}`;
|
|
60
|
+
const expressRequest = req.req;
|
|
61
|
+
if (expressRequest?.url?.startsWith(parsedRequestClass?.basePath)) {
|
|
62
|
+
expressRequest.url = expressRequest.url.split(parsedRequestClass?.basePath)[1] || '/';
|
|
63
|
+
expressRequest.originalUrl = expressRequest.url.split(parsedRequestClass?.basePath)[1] || '/';
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
logger.warn({
|
|
67
|
+
label: `request-processor-middleware`,
|
|
68
|
+
message: `The URL requested for doesn't start with the Base path`,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
60
71
|
}
|
|
61
72
|
else {
|
|
62
73
|
logger.debug({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { InternalAppServer, ServerContext, ServerTypes } from '@lwrjs/types';
|
|
2
2
|
export declare function viewMiddleware<T extends ServerTypes>(app: InternalAppServer<T>, context: ServerContext): void;
|
|
3
|
+
export declare function convertMetricsToArrayOfStrings(span: Record<string, any>): string;
|
|
3
4
|
//# sourceMappingURL=view-middleware.d.ts.map
|
|
@@ -4,6 +4,7 @@ import { decodeViewPath, extractRequestParams, getClientBootstrapConfigurationRo
|
|
|
4
4
|
import { RequestHandlerSpan, getTracer } from '@lwrjs/instrumentation';
|
|
5
5
|
import { handleErrors } from './utils/error-handling.js';
|
|
6
6
|
import { LwrViewHandler } from '@lwrjs/view-registry';
|
|
7
|
+
import { convertToReadableSpan } from '@lwrjs/instrumentation/aws-exporter';
|
|
7
8
|
function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
8
9
|
const errorRoute = errorRoutes.find((route) => route.status === 500);
|
|
9
10
|
const appConfig = context.appConfig;
|
|
@@ -37,11 +38,13 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
|
37
38
|
params: viewRequest.params,
|
|
38
39
|
query: viewRequest.query,
|
|
39
40
|
cookie: req.headers?.cookie,
|
|
41
|
+
coreProxy: req.getCoreProxy(appConfig.coreProxy ?? undefined, route.bootstrap?.proxyForSSR),
|
|
40
42
|
};
|
|
41
43
|
const resolve = req.isJsonRequest() ? viewHandler.getViewJson : viewHandler.getViewContent;
|
|
42
44
|
let viewResponse;
|
|
43
45
|
let resolvedRoute;
|
|
44
46
|
let traceId;
|
|
47
|
+
let reqSpan;
|
|
45
48
|
try {
|
|
46
49
|
viewResponse = await getTracer().trace({
|
|
47
50
|
name: RequestHandlerSpan.GetView,
|
|
@@ -54,6 +57,7 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
|
54
57
|
},
|
|
55
58
|
}, (span) => {
|
|
56
59
|
traceId = span.traceId;
|
|
60
|
+
reqSpan = span.reqSpan;
|
|
57
61
|
return resolve.call(viewHandler, viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
58
62
|
});
|
|
59
63
|
resolvedRoute = route;
|
|
@@ -93,6 +97,11 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
|
93
97
|
}
|
|
94
98
|
if (traceId?.length) {
|
|
95
99
|
res.setHeader('x-trace-id', traceId);
|
|
100
|
+
if (reqSpan?.status?.code === 0) {
|
|
101
|
+
res.set({
|
|
102
|
+
'X-Custom-Lwr-Metric': convertMetricsToArrayOfStrings(convertToReadableSpan(reqSpan)),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
96
105
|
}
|
|
97
106
|
let status = resolvedRoute.status || viewResponse.status || 200;
|
|
98
107
|
const redirect = viewResponse.metadata?.viewDefinition?.redirect;
|
|
@@ -247,4 +256,17 @@ function addRedirectQueryParam(redirectUrl, depth) {
|
|
|
247
256
|
url.searchParams.set(REQUEST_DEPTH_KEY, String(depth + 1));
|
|
248
257
|
return url.toString().replace(fakeOrigin, '');
|
|
249
258
|
}
|
|
259
|
+
export function convertMetricsToArrayOfStrings(span) {
|
|
260
|
+
const requiredMetrics = ['traceId', 'name', 'attributes', 'duration'];
|
|
261
|
+
return requiredMetrics.reduce((metricString, prop) => {
|
|
262
|
+
if (metricString && !metricString.endsWith('; ')) {
|
|
263
|
+
metricString += '; ';
|
|
264
|
+
}
|
|
265
|
+
if (span[prop]) {
|
|
266
|
+
const propValue = typeof span[prop] === 'object' ? JSON.stringify(span[prop]) : span[prop];
|
|
267
|
+
metricString += `${prop}: ${propValue}`;
|
|
268
|
+
}
|
|
269
|
+
return metricString;
|
|
270
|
+
}, '');
|
|
271
|
+
}
|
|
250
272
|
//# sourceMappingURL=view-middleware.js.map
|
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.18",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -43,44 +43,44 @@
|
|
|
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.18",
|
|
47
|
+
"@lwrjs/asset-registry": "0.15.0-alpha.18",
|
|
48
|
+
"@lwrjs/asset-transformer": "0.15.0-alpha.18",
|
|
49
|
+
"@lwrjs/base-view-provider": "0.15.0-alpha.18",
|
|
50
|
+
"@lwrjs/base-view-transformer": "0.15.0-alpha.18",
|
|
51
|
+
"@lwrjs/client-modules": "0.15.0-alpha.18",
|
|
52
|
+
"@lwrjs/config": "0.15.0-alpha.18",
|
|
53
|
+
"@lwrjs/diagnostics": "0.15.0-alpha.18",
|
|
54
|
+
"@lwrjs/esbuild": "0.15.0-alpha.18",
|
|
55
|
+
"@lwrjs/fs-asset-provider": "0.15.0-alpha.18",
|
|
56
|
+
"@lwrjs/fs-watch": "0.15.0-alpha.18",
|
|
57
|
+
"@lwrjs/html-view-provider": "0.15.0-alpha.18",
|
|
58
|
+
"@lwrjs/instrumentation": "0.15.0-alpha.18",
|
|
59
|
+
"@lwrjs/loader": "0.15.0-alpha.18",
|
|
60
|
+
"@lwrjs/lwc-module-provider": "0.15.0-alpha.18",
|
|
61
|
+
"@lwrjs/lwc-ssr": "0.15.0-alpha.18",
|
|
62
|
+
"@lwrjs/markdown-view-provider": "0.15.0-alpha.18",
|
|
63
|
+
"@lwrjs/module-bundler": "0.15.0-alpha.18",
|
|
64
|
+
"@lwrjs/module-registry": "0.15.0-alpha.18",
|
|
65
|
+
"@lwrjs/npm-module-provider": "0.15.0-alpha.18",
|
|
66
|
+
"@lwrjs/nunjucks-view-provider": "0.15.0-alpha.18",
|
|
67
|
+
"@lwrjs/o11y": "0.15.0-alpha.18",
|
|
68
|
+
"@lwrjs/resource-registry": "0.15.0-alpha.18",
|
|
69
|
+
"@lwrjs/router": "0.15.0-alpha.18",
|
|
70
|
+
"@lwrjs/server": "0.15.0-alpha.18",
|
|
71
|
+
"@lwrjs/shared-utils": "0.15.0-alpha.18",
|
|
72
|
+
"@lwrjs/static": "0.15.0-alpha.18",
|
|
73
|
+
"@lwrjs/view-registry": "0.15.0-alpha.18",
|
|
74
74
|
"chokidar": "^3.6.0",
|
|
75
75
|
"esbuild": "^0.9.7",
|
|
76
76
|
"fs-extra": "^11.2.0",
|
|
77
77
|
"path-to-regexp": "^6.2.2",
|
|
78
78
|
"qs": "^6.13.0",
|
|
79
|
-
"rollup": "^2.
|
|
79
|
+
"rollup": "^2.79.2",
|
|
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.18",
|
|
84
84
|
"@types/ws": "^8.5.12",
|
|
85
85
|
"memfs": "^4.9.3"
|
|
86
86
|
},
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"volta": {
|
|
94
94
|
"extends": "../../../package.json"
|
|
95
95
|
},
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "fefc639770948be769b1ace03b7759e7b8906cae"
|
|
97
97
|
}
|