@lwrjs/core 0.12.0-alpha.0 → 0.12.0-alpha.10
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/info/route-handler.cjs +149 -0
- package/build/cjs/middleware/asset-middleware.cjs +2 -1
- package/build/cjs/middleware/bundle-middleware.cjs +7 -1
- package/build/cjs/middleware/mapping-middleware.cjs +4 -1
- package/build/cjs/middleware/module-middleware.cjs +7 -1
- package/build/cjs/middleware/utils/identity.cjs +1 -1
- package/build/cjs/middleware/view-middleware.cjs +21 -5
- package/build/es/info/route-handler.d.ts +3 -0
- package/build/es/info/route-handler.js +123 -0
- package/build/es/middleware/asset-middleware.js +1 -0
- package/build/es/middleware/bundle-middleware.js +7 -0
- package/build/es/middleware/mapping-middleware.js +3 -0
- package/build/es/middleware/module-middleware.js +7 -0
- package/build/es/middleware/utils/identity.js +5 -1
- package/build/es/middleware/view-middleware.js +24 -4
- package/package.json +37 -32
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
11
|
+
};
|
|
12
|
+
var __exportStar = (target, module2, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toModule = (module2) => {
|
|
21
|
+
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// packages/@lwrjs/core/src/info/route-handler.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
default: () => siteInfoHandler
|
|
28
|
+
});
|
|
29
|
+
var import_config = __toModule(require("@lwrjs/config"));
|
|
30
|
+
var import_fs = __toModule(require("fs"));
|
|
31
|
+
var baseHtml = `<!DOCTYPE html>
|
|
32
|
+
<html lang="en">
|
|
33
|
+
<head>
|
|
34
|
+
<meta charset="utf-8" />
|
|
35
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
|
36
|
+
<title>Site Information</title>
|
|
37
|
+
<style>
|
|
38
|
+
body {
|
|
39
|
+
font-family: Arial, sans-serif;
|
|
40
|
+
margin: 0;
|
|
41
|
+
padding: 20px;
|
|
42
|
+
background-color: #f9f9f9;
|
|
43
|
+
color: #333;
|
|
44
|
+
display: flex;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.container {
|
|
48
|
+
max-width: 800px;
|
|
49
|
+
width: 100%;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
h1, h2 {
|
|
53
|
+
color: #555;
|
|
54
|
+
margin-bottom: 16px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
ul {
|
|
58
|
+
list-style-type: none;
|
|
59
|
+
padding: 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
li {
|
|
63
|
+
background-color: #fff;
|
|
64
|
+
border: 1px solid #ddd;
|
|
65
|
+
margin-bottom: 10px;
|
|
66
|
+
padding: 10px;
|
|
67
|
+
border-radius: 4px;
|
|
68
|
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
69
|
+
display: flex;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.key {
|
|
73
|
+
margin-right: 10px;
|
|
74
|
+
color: #777;
|
|
75
|
+
font-weight: normal;
|
|
76
|
+
min-width: 200px;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.val {
|
|
80
|
+
font-weight: bold;
|
|
81
|
+
color: steelblue;
|
|
82
|
+
font-size: 1.1em;
|
|
83
|
+
flex-grow: 1;
|
|
84
|
+
text-align: left;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.data-container {
|
|
88
|
+
padding: 20px;
|
|
89
|
+
border: 1px solid #333;
|
|
90
|
+
border-radius: 5px;
|
|
91
|
+
white-space: pre;
|
|
92
|
+
font-family: monospace;
|
|
93
|
+
text-align: justify;
|
|
94
|
+
};
|
|
95
|
+
</style>
|
|
96
|
+
</head>
|
|
97
|
+
<body>
|
|
98
|
+
<div class="container">
|
|
99
|
+
<h1>Site Information</h1>
|
|
100
|
+
<h2>Environment</h2>
|
|
101
|
+
{{ versionInfo }}
|
|
102
|
+
<h2>Metadata</h2>
|
|
103
|
+
{{ metadata }}
|
|
104
|
+
</div>
|
|
105
|
+
</body>
|
|
106
|
+
</html>
|
|
107
|
+
`;
|
|
108
|
+
async function siteInfoHandler(_request, context) {
|
|
109
|
+
const versionInfo = {
|
|
110
|
+
"LWR Version": import_config.LWR_VERSION,
|
|
111
|
+
"LWC Version": import_config.LWC_VERSION,
|
|
112
|
+
"Node Version": import_config.NODE_VERSION,
|
|
113
|
+
"PWA Kit Runtime Version": import_config.PWA_KIT_RUNTIME_VERSION
|
|
114
|
+
};
|
|
115
|
+
let versionInfoString = "<ul>";
|
|
116
|
+
for (const key in versionInfo) {
|
|
117
|
+
if (versionInfo[key] !== "note-provided") {
|
|
118
|
+
versionInfoString += `<li><span class="key">${key}:</span><span class="val">${versionInfo[key]}</span></li>
|
|
119
|
+
`;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
versionInfoString += "</ul>";
|
|
123
|
+
const providedMetadataPath = `${context.rootDir}/site/.metadata/runtime-info.json`;
|
|
124
|
+
let providedMetadata = {};
|
|
125
|
+
if (import_fs.default.existsSync(providedMetadataPath)) {
|
|
126
|
+
providedMetadata = JSON.parse(import_fs.default.readFileSync(providedMetadataPath, "utf-8"));
|
|
127
|
+
}
|
|
128
|
+
let providedInfoString = "<ul>";
|
|
129
|
+
for (const key in providedMetadata) {
|
|
130
|
+
if (providedMetadata[key] !== "note-provided") {
|
|
131
|
+
const value = typeof providedMetadata[key] === "object" ? `<div class="data-container val">${JSON.stringify(providedMetadata[key], null, 2)}</div>` : `<span class="val">${providedMetadata[key]}</span>`;
|
|
132
|
+
providedInfoString += `<li><span class="key">${key}:</span>${value}</li>
|
|
133
|
+
`;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
providedInfoString += "</ul>";
|
|
137
|
+
let infoHtml = baseHtml;
|
|
138
|
+
infoHtml = infoHtml.replace("{{ versionInfo }}", versionInfoString);
|
|
139
|
+
infoHtml = infoHtml.replace("{{ metadata }}", providedInfoString);
|
|
140
|
+
return {
|
|
141
|
+
body: infoHtml,
|
|
142
|
+
headers: {
|
|
143
|
+
"content-type": `text/html; charset=utf-8`
|
|
144
|
+
},
|
|
145
|
+
cache: {
|
|
146
|
+
ttl: "200s"
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
@@ -55,7 +55,8 @@ function createAssetMiddleware(context) {
|
|
|
55
55
|
const asset = await (0, import_instrumentation.getTracer)().trace({
|
|
56
56
|
name: import_instrumentation.RequestHandlerSpan.GetAsset,
|
|
57
57
|
attributes: {
|
|
58
|
-
specifier: assetId.specifier
|
|
58
|
+
specifier: assetId.specifier,
|
|
59
|
+
url: req.originalUrl
|
|
59
60
|
}
|
|
60
61
|
}, () => {
|
|
61
62
|
return assetRegistry.getAsset({...assetId, signature}, runtimeEnvironment, req.isSiteGeneration());
|
|
@@ -53,6 +53,11 @@ function createBundleMiddleware(context) {
|
|
|
53
53
|
res.send(import_diagnostics.descriptions.UNRESOLVABLE.INVALID_JSON().message);
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
|
+
if (!req.validateApiVersion(appConfig)) {
|
|
57
|
+
res.status(400);
|
|
58
|
+
res.send(import_diagnostics.descriptions.UNRESOLVABLE.INVALID_API_VERSION(req.params.apiVersion, appConfig.apiVersion).message);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
56
61
|
const {runtimeEnvironment, runtimeParams} = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
57
62
|
const importer = req.query.importer ? await (0, import_request.getRequestImporter)(req, moduleRegistry, runtimeParams) : void 0;
|
|
58
63
|
const {moduleId, signature} = (0, import_identity.getModuleIdentity)(req, importer);
|
|
@@ -64,7 +69,8 @@ function createBundleMiddleware(context) {
|
|
|
64
69
|
const bundleDefinition = await (0, import_instrumentation.getTracer)().trace({
|
|
65
70
|
name: import_instrumentation.RequestHandlerSpan.GetBundle,
|
|
66
71
|
attributes: {
|
|
67
|
-
specifier: moduleId.specifier
|
|
72
|
+
specifier: moduleId.specifier,
|
|
73
|
+
url: req.originalUrl
|
|
68
74
|
}
|
|
69
75
|
}, () => {
|
|
70
76
|
return moduleBundler.getModuleBundle(moduleId, {...runtimeEnvironment, bundle: true, sourceMapUrl}, runtimeParams);
|
|
@@ -47,7 +47,10 @@ function createMappingMiddleware(context) {
|
|
|
47
47
|
const {runtimeEnvironment, runtimeParams} = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
48
48
|
const {moduleIds} = (0, import_identity.getMappingIdentity)(req);
|
|
49
49
|
const importMetadata = await (0, import_instrumentation.getTracer)().trace({
|
|
50
|
-
name: import_instrumentation.RequestHandlerSpan.GetMapping
|
|
50
|
+
name: import_instrumentation.RequestHandlerSpan.GetMapping,
|
|
51
|
+
attributes: {
|
|
52
|
+
url: req.originalUrl
|
|
53
|
+
}
|
|
51
54
|
}, () => {
|
|
52
55
|
return (0, import_shared_utils.getImportMetadataMappings)(moduleIds, runtimeEnvironment, runtimeParams, moduleRegistry, moduleBundler);
|
|
53
56
|
});
|
|
@@ -47,6 +47,11 @@ function createModuleMiddleware(context) {
|
|
|
47
47
|
res.send(import_diagnostics.descriptions.UNRESOLVABLE.INVALID_JSON().message);
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
+
if (!req.validateApiVersion(appConfig)) {
|
|
51
|
+
res.status(400);
|
|
52
|
+
res.send(import_diagnostics.descriptions.UNRESOLVABLE.INVALID_API_VERSION(req.params.apiVersion, appConfig.apiVersion).message);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
50
55
|
const {runtimeEnvironment, runtimeParams} = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
51
56
|
const importer = req.query.importer ? await (0, import_request.getRequestImporter)(req, moduleRegistry, runtimeParams) : void 0;
|
|
52
57
|
const {moduleId, signature} = (0, import_identity.getModuleIdentity)(req, importer);
|
|
@@ -57,7 +62,8 @@ function createModuleMiddleware(context) {
|
|
|
57
62
|
const moduleDefinition = await (0, import_instrumentation.getTracer)().trace({
|
|
58
63
|
name: import_instrumentation.RequestHandlerSpan.GetModule,
|
|
59
64
|
attributes: {
|
|
60
|
-
specifier: moduleId.specifier
|
|
65
|
+
specifier: moduleId.specifier,
|
|
66
|
+
url: req.originalUrl
|
|
61
67
|
}
|
|
62
68
|
}, () => {
|
|
63
69
|
return moduleRegistry.getLinkedModule(moduleId, {...runtimeEnvironment, bundle: false}, runtimeParams);
|
|
@@ -75,7 +75,7 @@ function getResourceIdentity(req) {
|
|
|
75
75
|
}
|
|
76
76
|
function getAssetIdentity(req) {
|
|
77
77
|
const {signature, immutable, assetType: type} = req.params;
|
|
78
|
-
const specifier = type ? "/" + req.params[0] : req.originalUrl.split("?")[0];
|
|
78
|
+
const specifier = type ? process.platform === "win32" ? req.params[0] : "/" + req.params[0] : req.originalUrl.split("?")[0];
|
|
79
79
|
if (validateSpecifier(specifier) === false) {
|
|
80
80
|
throw (0, import_diagnostics.createSingleDiagnosticError)({
|
|
81
81
|
description: import_diagnostics.descriptions.UNRESOLVABLE.INVALID_SPECIFIER(specifier)
|
|
@@ -70,7 +70,8 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
|
70
70
|
viewResponse = await (0, import_instrumentation.getTracer)().trace({
|
|
71
71
|
name: import_instrumentation.RequestHandlerSpan.GetView,
|
|
72
72
|
attributes: {
|
|
73
|
-
view: route.id
|
|
73
|
+
view: route.id,
|
|
74
|
+
url: req.originalUrl
|
|
74
75
|
}
|
|
75
76
|
}, () => {
|
|
76
77
|
return resolve.call(viewHandler, viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
@@ -112,7 +113,7 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
|
112
113
|
}
|
|
113
114
|
function createConfigMiddleware(routes, context, viewHandler) {
|
|
114
115
|
return async (req, res) => {
|
|
115
|
-
const {runtimeEnvironment, runtimeParams} = req.getRuntimeContext(context.runtimeEnvironment);
|
|
116
|
+
const {runtimeEnvironment, runtimeParams: defaultRuntimeParams} = req.getRuntimeContext(context.runtimeEnvironment);
|
|
116
117
|
const {appId, encodedViewPath} = req.params;
|
|
117
118
|
const route = routes.find((route2) => route2.id === appId);
|
|
118
119
|
if (!route) {
|
|
@@ -120,16 +121,31 @@ function createConfigMiddleware(routes, context, viewHandler) {
|
|
|
120
121
|
return;
|
|
121
122
|
}
|
|
122
123
|
const url = (0, import_shared_utils.decodeViewPath)(encodedViewPath);
|
|
124
|
+
let requestPath = url;
|
|
125
|
+
const query = {};
|
|
126
|
+
if (url.indexOf("?") !== -1) {
|
|
127
|
+
requestPath = url.substring(0, url.indexOf("?"));
|
|
128
|
+
const searchParams = new URLSearchParams(url.substring(url.indexOf("?")));
|
|
129
|
+
for (const [key, value] of searchParams.entries()) {
|
|
130
|
+
query[key] = value;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
123
133
|
const originalUrl = req.originalUrl;
|
|
124
|
-
const
|
|
125
|
-
const params = (0, import_shared_utils.extractRequestParams)(
|
|
134
|
+
const routePath = route.path;
|
|
135
|
+
const params = (0, import_shared_utils.extractRequestParams)(routePath, url, req.params);
|
|
126
136
|
const viewRequest = {
|
|
127
137
|
url,
|
|
128
138
|
originalUrl,
|
|
129
139
|
params,
|
|
130
|
-
query
|
|
140
|
+
query,
|
|
131
141
|
requestPath
|
|
132
142
|
};
|
|
143
|
+
const runtimeParams = {
|
|
144
|
+
...defaultRuntimeParams,
|
|
145
|
+
url: viewRequest.url,
|
|
146
|
+
params: viewRequest.params,
|
|
147
|
+
query: viewRequest.query
|
|
148
|
+
};
|
|
133
149
|
const viewResponse = await viewHandler.getViewConfiguration(viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
134
150
|
if (!viewResponse) {
|
|
135
151
|
res.status(404).send(import_diagnostics.descriptions.UNRESOLVABLE.VIEW_CONFIG(url).message);
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { LWC_VERSION, LWR_VERSION, PWA_KIT_RUNTIME_VERSION, NODE_VERSION } from '@lwrjs/config';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
const baseHtml = `<!DOCTYPE html>
|
|
4
|
+
<html lang="en">
|
|
5
|
+
<head>
|
|
6
|
+
<meta charset="utf-8" />
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
|
|
8
|
+
<title>Site Information</title>
|
|
9
|
+
<style>
|
|
10
|
+
body {
|
|
11
|
+
font-family: Arial, sans-serif;
|
|
12
|
+
margin: 0;
|
|
13
|
+
padding: 20px;
|
|
14
|
+
background-color: #f9f9f9;
|
|
15
|
+
color: #333;
|
|
16
|
+
display: flex;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.container {
|
|
20
|
+
max-width: 800px;
|
|
21
|
+
width: 100%;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
h1, h2 {
|
|
25
|
+
color: #555;
|
|
26
|
+
margin-bottom: 16px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
ul {
|
|
30
|
+
list-style-type: none;
|
|
31
|
+
padding: 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
li {
|
|
35
|
+
background-color: #fff;
|
|
36
|
+
border: 1px solid #ddd;
|
|
37
|
+
margin-bottom: 10px;
|
|
38
|
+
padding: 10px;
|
|
39
|
+
border-radius: 4px;
|
|
40
|
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
41
|
+
display: flex;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.key {
|
|
45
|
+
margin-right: 10px;
|
|
46
|
+
color: #777;
|
|
47
|
+
font-weight: normal;
|
|
48
|
+
min-width: 200px;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.val {
|
|
52
|
+
font-weight: bold;
|
|
53
|
+
color: steelblue;
|
|
54
|
+
font-size: 1.1em;
|
|
55
|
+
flex-grow: 1;
|
|
56
|
+
text-align: left;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.data-container {
|
|
60
|
+
padding: 20px;
|
|
61
|
+
border: 1px solid #333;
|
|
62
|
+
border-radius: 5px;
|
|
63
|
+
white-space: pre;
|
|
64
|
+
font-family: monospace;
|
|
65
|
+
text-align: justify;
|
|
66
|
+
};
|
|
67
|
+
</style>
|
|
68
|
+
</head>
|
|
69
|
+
<body>
|
|
70
|
+
<div class="container">
|
|
71
|
+
<h1>Site Information</h1>
|
|
72
|
+
<h2>Environment</h2>
|
|
73
|
+
{{ versionInfo }}
|
|
74
|
+
<h2>Metadata</h2>
|
|
75
|
+
{{ metadata }}
|
|
76
|
+
</div>
|
|
77
|
+
</body>
|
|
78
|
+
</html>
|
|
79
|
+
`;
|
|
80
|
+
export default async function siteInfoHandler(_request, context) {
|
|
81
|
+
const versionInfo = {
|
|
82
|
+
'LWR Version': LWR_VERSION,
|
|
83
|
+
'LWC Version': LWC_VERSION,
|
|
84
|
+
'Node Version': NODE_VERSION,
|
|
85
|
+
'PWA Kit Runtime Version': PWA_KIT_RUNTIME_VERSION,
|
|
86
|
+
};
|
|
87
|
+
let versionInfoString = '<ul>';
|
|
88
|
+
for (const key in versionInfo) {
|
|
89
|
+
if (versionInfo[key] !== 'note-provided') {
|
|
90
|
+
versionInfoString += `<li><span class="key">${key}:</span><span class="val">${versionInfo[key]}</span></li>\n`;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
versionInfoString += '</ul>';
|
|
94
|
+
// Get any provided metadata from site/.metadata/runtime-info.json
|
|
95
|
+
const providedMetadataPath = `${context.rootDir}/site/.metadata/runtime-info.json`;
|
|
96
|
+
let providedMetadata = {};
|
|
97
|
+
if (fs.existsSync(providedMetadataPath)) {
|
|
98
|
+
providedMetadata = JSON.parse(fs.readFileSync(providedMetadataPath, 'utf-8'));
|
|
99
|
+
}
|
|
100
|
+
let providedInfoString = '<ul>';
|
|
101
|
+
for (const key in providedMetadata) {
|
|
102
|
+
if (providedMetadata[key] !== 'note-provided') {
|
|
103
|
+
const value = typeof providedMetadata[key] === 'object'
|
|
104
|
+
? `<div class="data-container val">${JSON.stringify(providedMetadata[key], null, 2)}</div>`
|
|
105
|
+
: `<span class="val">${providedMetadata[key]}</span>`;
|
|
106
|
+
providedInfoString += `<li><span class="key">${key}:</span>${value}</li>\n`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
providedInfoString += '</ul>';
|
|
110
|
+
let infoHtml = baseHtml;
|
|
111
|
+
infoHtml = infoHtml.replace('{{ versionInfo }}', versionInfoString);
|
|
112
|
+
infoHtml = infoHtml.replace('{{ metadata }}', providedInfoString);
|
|
113
|
+
return {
|
|
114
|
+
body: infoHtml,
|
|
115
|
+
headers: {
|
|
116
|
+
'content-type': `text/html; charset=utf-8`,
|
|
117
|
+
},
|
|
118
|
+
cache: {
|
|
119
|
+
ttl: '200s',
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=route-handler.js.map
|
|
@@ -26,6 +26,7 @@ function createAssetMiddleware(context) {
|
|
|
26
26
|
name: RequestHandlerSpan.GetAsset,
|
|
27
27
|
attributes: {
|
|
28
28
|
specifier: assetId.specifier,
|
|
29
|
+
url: req.originalUrl,
|
|
29
30
|
},
|
|
30
31
|
}, () => {
|
|
31
32
|
return assetRegistry.getAsset({ ...assetId, signature }, runtimeEnvironment, req.isSiteGeneration());
|
|
@@ -20,6 +20,12 @@ function createBundleMiddleware(context) {
|
|
|
20
20
|
res.send(descriptions.UNRESOLVABLE.INVALID_JSON().message);
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
+
if (!req.validateApiVersion(appConfig)) {
|
|
24
|
+
res.status(400);
|
|
25
|
+
res.send(descriptions.UNRESOLVABLE.INVALID_API_VERSION(req.params.apiVersion, appConfig.apiVersion)
|
|
26
|
+
.message);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
23
29
|
const { runtimeEnvironment, runtimeParams } = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
24
30
|
const importer = req.query.importer
|
|
25
31
|
? await getRequestImporter(req, moduleRegistry, runtimeParams)
|
|
@@ -34,6 +40,7 @@ function createBundleMiddleware(context) {
|
|
|
34
40
|
name: RequestHandlerSpan.GetBundle,
|
|
35
41
|
attributes: {
|
|
36
42
|
specifier: moduleId.specifier,
|
|
43
|
+
url: req.originalUrl,
|
|
37
44
|
},
|
|
38
45
|
}, () => {
|
|
39
46
|
return moduleBundler.getModuleBundle(moduleId,
|
|
@@ -15,6 +15,9 @@ function createMappingMiddleware(context) {
|
|
|
15
15
|
const { moduleIds } = getMappingIdentity(req);
|
|
16
16
|
const importMetadata = await getTracer().trace({
|
|
17
17
|
name: RequestHandlerSpan.GetMapping,
|
|
18
|
+
attributes: {
|
|
19
|
+
url: req.originalUrl,
|
|
20
|
+
},
|
|
18
21
|
}, () => {
|
|
19
22
|
return getImportMetadataMappings(moduleIds, runtimeEnvironment, runtimeParams, moduleRegistry, moduleBundler);
|
|
20
23
|
});
|
|
@@ -19,6 +19,12 @@ function createModuleMiddleware(context) {
|
|
|
19
19
|
res.send(descriptions.UNRESOLVABLE.INVALID_JSON().message);
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
+
if (!req.validateApiVersion(appConfig)) {
|
|
23
|
+
res.status(400);
|
|
24
|
+
res.send(descriptions.UNRESOLVABLE.INVALID_API_VERSION(req.params.apiVersion, appConfig.apiVersion)
|
|
25
|
+
.message);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
22
28
|
const { runtimeEnvironment, runtimeParams } = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
23
29
|
const importer = req.query.importer
|
|
24
30
|
? await getRequestImporter(req, moduleRegistry, runtimeParams)
|
|
@@ -32,6 +38,7 @@ function createModuleMiddleware(context) {
|
|
|
32
38
|
name: RequestHandlerSpan.GetModule,
|
|
33
39
|
attributes: {
|
|
34
40
|
specifier: moduleId.specifier,
|
|
41
|
+
url: req.originalUrl,
|
|
35
42
|
},
|
|
36
43
|
}, () => {
|
|
37
44
|
return moduleRegistry.getLinkedModule(moduleId,
|
|
@@ -44,7 +44,11 @@ export function getResourceIdentity(req) {
|
|
|
44
44
|
}
|
|
45
45
|
export function getAssetIdentity(req) {
|
|
46
46
|
const { signature, immutable, assetType: type } = req.params;
|
|
47
|
-
const specifier = type
|
|
47
|
+
const specifier = type
|
|
48
|
+
? process.platform === 'win32'
|
|
49
|
+
? req.params[0]
|
|
50
|
+
: '/' + req.params[0]
|
|
51
|
+
: req.originalUrl.split('?')[0];
|
|
48
52
|
if (validateSpecifier(specifier) === false) {
|
|
49
53
|
throw createSingleDiagnosticError({
|
|
50
54
|
description: descriptions.UNRESOLVABLE.INVALID_SPECIFIER(specifier),
|
|
@@ -45,6 +45,7 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
|
45
45
|
name: RequestHandlerSpan.GetView,
|
|
46
46
|
attributes: {
|
|
47
47
|
view: route.id,
|
|
48
|
+
url: req.originalUrl,
|
|
48
49
|
},
|
|
49
50
|
}, () => {
|
|
50
51
|
return resolve.call(viewHandler, viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
@@ -91,7 +92,7 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
|
91
92
|
}
|
|
92
93
|
function createConfigMiddleware(routes, context, viewHandler) {
|
|
93
94
|
return async (req, res) => {
|
|
94
|
-
const { runtimeEnvironment, runtimeParams } = req.getRuntimeContext(context.runtimeEnvironment);
|
|
95
|
+
const { runtimeEnvironment, runtimeParams: defaultRuntimeParams } = req.getRuntimeContext(context.runtimeEnvironment);
|
|
95
96
|
const { appId, encodedViewPath } = req.params;
|
|
96
97
|
// match the app id to a route
|
|
97
98
|
const route = routes.find((route) => route.id === appId);
|
|
@@ -101,16 +102,35 @@ function createConfigMiddleware(routes, context, viewHandler) {
|
|
|
101
102
|
}
|
|
102
103
|
// decode the resolved view path and extract any params.
|
|
103
104
|
const url = decodeViewPath(encodedViewPath);
|
|
105
|
+
let requestPath = url;
|
|
106
|
+
// Create an empty object to store the key-value pairs
|
|
107
|
+
const query = {};
|
|
108
|
+
if (url.indexOf('?') !== -1) {
|
|
109
|
+
// Remove query string from the requestPath
|
|
110
|
+
requestPath = url.substring(0, url.indexOf('?'));
|
|
111
|
+
const searchParams = new URLSearchParams(url.substring(url.indexOf('?')));
|
|
112
|
+
// Iterate over the entries of the URLSearchParams and populate the object
|
|
113
|
+
for (const [key, value] of searchParams.entries()) {
|
|
114
|
+
query[key] = value;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
104
117
|
const originalUrl = req.originalUrl;
|
|
105
|
-
const
|
|
106
|
-
const params = extractRequestParams(
|
|
118
|
+
const routePath = route.path;
|
|
119
|
+
const params = extractRequestParams(routePath, url, req.params);
|
|
107
120
|
const viewRequest = {
|
|
108
121
|
url,
|
|
109
122
|
originalUrl,
|
|
110
123
|
params,
|
|
111
|
-
query
|
|
124
|
+
query,
|
|
112
125
|
requestPath,
|
|
113
126
|
};
|
|
127
|
+
// Augment runtime params with viewRequest info
|
|
128
|
+
const runtimeParams = {
|
|
129
|
+
...defaultRuntimeParams,
|
|
130
|
+
url: viewRequest.url,
|
|
131
|
+
params: viewRequest.params,
|
|
132
|
+
query: viewRequest.query,
|
|
133
|
+
};
|
|
114
134
|
const viewResponse = await viewHandler.getViewConfiguration(viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
115
135
|
if (!viewResponse) {
|
|
116
136
|
res.status(404).send(descriptions.UNRESOLVABLE.VIEW_CONFIG(url).message);
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.12.0-alpha.
|
|
7
|
+
"version": "0.12.0-alpha.10",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -27,7 +27,11 @@
|
|
|
27
27
|
"import": "./build/es/middleware.js",
|
|
28
28
|
"require": "./build/cjs/middleware.cjs"
|
|
29
29
|
},
|
|
30
|
-
"./package": "./package.cjs"
|
|
30
|
+
"./package": "./package.cjs",
|
|
31
|
+
"./info/route-handler": {
|
|
32
|
+
"import": "./build/es/info/route-handler.js",
|
|
33
|
+
"require": "./build/cjs/info/route-handler.cjs"
|
|
34
|
+
}
|
|
31
35
|
},
|
|
32
36
|
"files": [
|
|
33
37
|
"build/**/*.js",
|
|
@@ -39,33 +43,34 @@
|
|
|
39
43
|
"build": "tsc -b"
|
|
40
44
|
},
|
|
41
45
|
"dependencies": {
|
|
42
|
-
"@lwrjs/app-service": "0.12.0-alpha.
|
|
43
|
-
"@lwrjs/asset-registry": "0.12.0-alpha.
|
|
44
|
-
"@lwrjs/asset-transformer": "0.12.0-alpha.
|
|
45
|
-
"@lwrjs/base-view-provider": "0.12.0-alpha.
|
|
46
|
-
"@lwrjs/base-view-transformer": "0.12.0-alpha.
|
|
47
|
-
"@lwrjs/client-modules": "0.12.0-alpha.
|
|
48
|
-
"@lwrjs/config": "0.12.0-alpha.
|
|
49
|
-
"@lwrjs/diagnostics": "0.12.0-alpha.
|
|
50
|
-
"@lwrjs/esbuild": "0.12.0-alpha.
|
|
51
|
-
"@lwrjs/fs-asset-provider": "0.12.0-alpha.
|
|
52
|
-
"@lwrjs/fs-watch": "0.12.0-alpha.
|
|
53
|
-
"@lwrjs/html-view-provider": "0.12.0-alpha.
|
|
54
|
-
"@lwrjs/instrumentation": "0.12.0-alpha.
|
|
55
|
-
"@lwrjs/loader": "0.12.0-alpha.
|
|
56
|
-
"@lwrjs/lwc-module-provider": "0.12.0-alpha.
|
|
57
|
-
"@lwrjs/
|
|
58
|
-
"@lwrjs/
|
|
59
|
-
"@lwrjs/module-
|
|
60
|
-
"@lwrjs/
|
|
61
|
-
"@lwrjs/
|
|
62
|
-
"@lwrjs/
|
|
63
|
-
"@lwrjs/
|
|
64
|
-
"@lwrjs/
|
|
65
|
-
"@lwrjs/
|
|
66
|
-
"@lwrjs/
|
|
67
|
-
"@lwrjs/
|
|
68
|
-
"@lwrjs/
|
|
46
|
+
"@lwrjs/app-service": "0.12.0-alpha.10",
|
|
47
|
+
"@lwrjs/asset-registry": "0.12.0-alpha.10",
|
|
48
|
+
"@lwrjs/asset-transformer": "0.12.0-alpha.10",
|
|
49
|
+
"@lwrjs/base-view-provider": "0.12.0-alpha.10",
|
|
50
|
+
"@lwrjs/base-view-transformer": "0.12.0-alpha.10",
|
|
51
|
+
"@lwrjs/client-modules": "0.12.0-alpha.10",
|
|
52
|
+
"@lwrjs/config": "0.12.0-alpha.10",
|
|
53
|
+
"@lwrjs/diagnostics": "0.12.0-alpha.10",
|
|
54
|
+
"@lwrjs/esbuild": "0.12.0-alpha.10",
|
|
55
|
+
"@lwrjs/fs-asset-provider": "0.12.0-alpha.10",
|
|
56
|
+
"@lwrjs/fs-watch": "0.12.0-alpha.10",
|
|
57
|
+
"@lwrjs/html-view-provider": "0.12.0-alpha.10",
|
|
58
|
+
"@lwrjs/instrumentation": "0.12.0-alpha.10",
|
|
59
|
+
"@lwrjs/loader": "0.12.0-alpha.10",
|
|
60
|
+
"@lwrjs/lwc-module-provider": "0.12.0-alpha.10",
|
|
61
|
+
"@lwrjs/lwc-ssr": "0.12.0-alpha.10",
|
|
62
|
+
"@lwrjs/markdown-view-provider": "0.12.0-alpha.10",
|
|
63
|
+
"@lwrjs/module-bundler": "0.12.0-alpha.10",
|
|
64
|
+
"@lwrjs/module-registry": "0.12.0-alpha.10",
|
|
65
|
+
"@lwrjs/npm-module-provider": "0.12.0-alpha.10",
|
|
66
|
+
"@lwrjs/nunjucks-view-provider": "0.12.0-alpha.10",
|
|
67
|
+
"@lwrjs/o11y": "0.12.0-alpha.10",
|
|
68
|
+
"@lwrjs/resource-registry": "0.12.0-alpha.10",
|
|
69
|
+
"@lwrjs/router": "0.12.0-alpha.10",
|
|
70
|
+
"@lwrjs/server": "0.12.0-alpha.10",
|
|
71
|
+
"@lwrjs/shared-utils": "0.12.0-alpha.10",
|
|
72
|
+
"@lwrjs/static": "0.12.0-alpha.10",
|
|
73
|
+
"@lwrjs/view-registry": "0.12.0-alpha.10",
|
|
69
74
|
"chokidar": "^3.5.3",
|
|
70
75
|
"esbuild": "^0.9.7",
|
|
71
76
|
"fs-extra": "^11.1.1",
|
|
@@ -75,17 +80,17 @@
|
|
|
75
80
|
"ws": "^8.8.1"
|
|
76
81
|
},
|
|
77
82
|
"devDependencies": {
|
|
78
|
-
"@lwrjs/types": "0.12.0-alpha.
|
|
83
|
+
"@lwrjs/types": "0.12.0-alpha.10",
|
|
79
84
|
"@types/ws": "^8.5.3"
|
|
80
85
|
},
|
|
81
86
|
"peerDependencies": {
|
|
82
87
|
"lwc": ">= 2.x"
|
|
83
88
|
},
|
|
84
89
|
"engines": {
|
|
85
|
-
"node": ">=
|
|
90
|
+
"node": ">=18.0.0"
|
|
86
91
|
},
|
|
87
92
|
"volta": {
|
|
88
93
|
"extends": "../../../package.json"
|
|
89
94
|
},
|
|
90
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "36759959f624aa40d371dc9ee698dd472813f19c"
|
|
91
96
|
}
|