@lwrjs/core 0.11.0-alpha.9 → 0.11.0
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/server.cjs +1 -1
- package/build/cjs/index.cjs +1 -1
- package/build/cjs/middleware/asset-middleware.cjs +10 -2
- package/build/cjs/middleware/bundle-middleware.cjs +20 -7
- package/build/cjs/middleware/hmr-middleware.cjs +6 -5
- package/build/cjs/middleware/locale-middleware.cjs +3 -1
- package/build/cjs/middleware/mapping-middleware.cjs +14 -4
- package/build/cjs/middleware/module-middleware.cjs +12 -4
- package/build/cjs/middleware/request-processor-middleware.cjs +5 -5
- package/build/cjs/middleware/resource-middleware.cjs +3 -3
- package/build/cjs/middleware/utils/error-handling.cjs +5 -4
- package/build/cjs/middleware/view-middleware.cjs +37 -8
- package/build/cjs/tools/server-warmup.cjs +6 -6
- package/build/cjs/tools/static-generation.cjs +72 -66
- package/build/cjs/tools/utils/network-dispatcher.cjs +12 -11
- package/build/es/context/server.js +1 -2
- package/build/es/index.js +2 -2
- package/build/es/middleware/asset-middleware.js +10 -2
- package/build/es/middleware/bundle-middleware.js +17 -9
- package/build/es/middleware/hmr-middleware.js +6 -5
- package/build/es/middleware/locale-middleware.js +1 -1
- package/build/es/middleware/mapping-middleware.js +9 -4
- package/build/es/middleware/module-middleware.js +14 -6
- package/build/es/middleware/request-processor-middleware.js +1 -1
- package/build/es/middleware/resource-middleware.js +3 -3
- package/build/es/middleware/utils/error-handling.js +5 -4
- package/build/es/middleware/view-middleware.js +48 -8
- package/build/es/tools/server-warmup.js +2 -2
- package/build/es/tools/static-generation.d.ts +4 -0
- package/build/es/tools/static-generation.js +66 -52
- package/build/es/tools/types.d.ts +2 -1
- package/build/es/tools/utils/network-dispatcher.js +2 -1
- package/package.json +31 -29
|
@@ -32,7 +32,7 @@ var import_module_registry = __toModule(require("@lwrjs/module-registry"));
|
|
|
32
32
|
var import_resource_registry = __toModule(require("@lwrjs/resource-registry"));
|
|
33
33
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
34
34
|
var import_view_registry = __toModule(require("@lwrjs/view-registry"));
|
|
35
|
-
var import_fs_watch = __toModule(require("@lwrjs/
|
|
35
|
+
var import_fs_watch = __toModule(require("@lwrjs/fs-watch"));
|
|
36
36
|
function createServerContext(appConfig, runtimeEnvironment, globalData) {
|
|
37
37
|
const appObserver = new import_shared_utils.LwrApplicationObserver();
|
|
38
38
|
const appEmitter = appObserver.createLwrEmitter();
|
package/build/cjs/index.cjs
CHANGED
|
@@ -192,7 +192,7 @@ async function generateStaticSite(config) {
|
|
|
192
192
|
config.serverType = "fs";
|
|
193
193
|
const {serverMode} = config;
|
|
194
194
|
if (serverMode === "dev" || serverMode === "compat") {
|
|
195
|
-
|
|
195
|
+
import_diagnostics.logger.warn("static generation in `dev` or `compat` mode is currently not fully supported");
|
|
196
196
|
}
|
|
197
197
|
const lwrApp = createServer(config);
|
|
198
198
|
overrideConfigAsSrc(lwrApp);
|
|
@@ -27,9 +27,10 @@ __export(exports, {
|
|
|
27
27
|
assetMiddleware: () => assetMiddleware
|
|
28
28
|
});
|
|
29
29
|
var import_path = __toModule(require("path"));
|
|
30
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
31
|
+
var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
|
|
30
32
|
var import_identity = __toModule(require("./utils/identity.cjs"));
|
|
31
33
|
var import_error_handling = __toModule(require("./utils/error-handling.cjs"));
|
|
32
|
-
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
33
34
|
function createAssetMiddleware(context) {
|
|
34
35
|
const {
|
|
35
36
|
assetRegistry,
|
|
@@ -51,7 +52,14 @@ function createAssetMiddleware(context) {
|
|
|
51
52
|
res.sendStatus(302);
|
|
52
53
|
return;
|
|
53
54
|
}
|
|
54
|
-
const asset = await
|
|
55
|
+
const asset = await (0, import_instrumentation.getTracer)().trace({
|
|
56
|
+
name: import_instrumentation.RequestHandlerSpan.GetAsset,
|
|
57
|
+
attributes: {
|
|
58
|
+
specifier: assetId.specifier
|
|
59
|
+
}
|
|
60
|
+
}, () => {
|
|
61
|
+
return assetRegistry.getAsset({...assetId, signature}, runtimeEnvironment, req.isSiteGeneration());
|
|
62
|
+
});
|
|
55
63
|
if (req.isSiteGeneration()) {
|
|
56
64
|
res.setSiteGenerationMetadata({asset});
|
|
57
65
|
}
|
|
@@ -28,16 +28,22 @@ __export(exports, {
|
|
|
28
28
|
});
|
|
29
29
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
30
30
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
31
|
+
var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
|
|
31
32
|
var import_request = __toModule(require("./utils/request.cjs"));
|
|
32
33
|
var import_identity = __toModule(require("./utils/identity.cjs"));
|
|
33
34
|
var import_metadata = __toModule(require("./utils/metadata.cjs"));
|
|
34
35
|
var import_unsigned_module_redirect = __toModule(require("./redirects/unsigned-module-redirect.cjs"));
|
|
35
36
|
var import_error_handling = __toModule(require("./utils/error-handling.cjs"));
|
|
36
37
|
function createBundleMiddleware(context) {
|
|
37
|
-
const {
|
|
38
|
+
const {
|
|
39
|
+
appConfig,
|
|
40
|
+
moduleRegistry,
|
|
41
|
+
moduleBundler,
|
|
42
|
+
runtimeEnvironment: defaultRuntimeEnvironment
|
|
43
|
+
} = context;
|
|
38
44
|
const unsignedBundleRedirect = (0, import_unsigned_module_redirect.createUnsignedBundleRedirect)(moduleBundler);
|
|
39
45
|
return async (req, res) => {
|
|
40
|
-
if (!req.validateEnvironmentRequest(
|
|
46
|
+
if (!req.validateEnvironmentRequest(appConfig)) {
|
|
41
47
|
res.status(400);
|
|
42
48
|
res.send(import_diagnostics.descriptions.UNRESOLVABLE.INVALID_ENVIRONMENT(req.params.environment).message);
|
|
43
49
|
return;
|
|
@@ -47,7 +53,7 @@ function createBundleMiddleware(context) {
|
|
|
47
53
|
res.send(import_diagnostics.descriptions.UNRESOLVABLE.INVALID_JSON().message);
|
|
48
54
|
return;
|
|
49
55
|
}
|
|
50
|
-
const {runtimeEnvironment, runtimeParams} = req.getRuntimeContext(
|
|
56
|
+
const {runtimeEnvironment, runtimeParams} = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
51
57
|
const importer = req.query.importer ? await (0, import_request.getRequestImporter)(req, moduleRegistry, runtimeParams) : void 0;
|
|
52
58
|
const {moduleId, signature} = (0, import_identity.getModuleIdentity)(req, importer);
|
|
53
59
|
if (moduleId.importer || !signature) {
|
|
@@ -55,7 +61,14 @@ function createBundleMiddleware(context) {
|
|
|
55
61
|
return;
|
|
56
62
|
}
|
|
57
63
|
const sourceMapUrl = req.path.replace("/bundle/", "/sourcemaps/bundle/");
|
|
58
|
-
const bundleDefinition = await
|
|
64
|
+
const bundleDefinition = await (0, import_instrumentation.getTracer)().trace({
|
|
65
|
+
name: import_instrumentation.RequestHandlerSpan.GetBundle,
|
|
66
|
+
attributes: {
|
|
67
|
+
specifier: moduleId.specifier
|
|
68
|
+
}
|
|
69
|
+
}, () => {
|
|
70
|
+
return moduleBundler.getModuleBundle(moduleId, {...runtimeEnvironment, bundle: true, sourceMapUrl}, runtimeParams);
|
|
71
|
+
});
|
|
59
72
|
if (req.isSiteGeneration()) {
|
|
60
73
|
res.setSiteGenerationMetadata({
|
|
61
74
|
moduleDefinition: bundleDefinition,
|
|
@@ -69,14 +82,14 @@ function createBundleMiddleware(context) {
|
|
|
69
82
|
};
|
|
70
83
|
}
|
|
71
84
|
function createSourceMapMiddleware(context) {
|
|
72
|
-
const {moduleBundler} = context;
|
|
85
|
+
const {appConfig, moduleBundler, runtimeEnvironment: defaultRuntimeEnvironment} = context;
|
|
73
86
|
return async (req, res) => {
|
|
74
|
-
if (!req.validateEnvironmentRequest(
|
|
87
|
+
if (!req.validateEnvironmentRequest(appConfig)) {
|
|
75
88
|
res.status(400);
|
|
76
89
|
res.send(import_diagnostics.descriptions.UNRESOLVABLE.INVALID_ENVIRONMENT(req.params.environment).message);
|
|
77
90
|
return;
|
|
78
91
|
}
|
|
79
|
-
const {runtimeEnvironment} = req.getRuntimeContext(
|
|
92
|
+
const {runtimeEnvironment} = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
80
93
|
const {moduleId, signature} = (0, import_identity.getModuleIdentity)(req);
|
|
81
94
|
const bundleDef = await moduleBundler.getModuleBundle(moduleId, runtimeEnvironment);
|
|
82
95
|
if (signature !== import_shared_utils.LATEST_SIGNATURE) {
|
|
@@ -27,6 +27,7 @@ __export(exports, {
|
|
|
27
27
|
hmrMiddleware: () => hmrMiddleware
|
|
28
28
|
});
|
|
29
29
|
var import_ws = __toModule(require("ws"));
|
|
30
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
30
31
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
31
32
|
var import_request = __toModule(require("./utils/request.cjs"));
|
|
32
33
|
var hmr;
|
|
@@ -60,9 +61,9 @@ var Hmr = class {
|
|
|
60
61
|
});
|
|
61
62
|
wss.on("error", (error) => {
|
|
62
63
|
if (error.code === "EADDRINUSE") {
|
|
63
|
-
|
|
64
|
+
import_diagnostics.logger.error(`HMR Socket Server: Port ${this.context.appConfig.port} already in use.`);
|
|
64
65
|
} else {
|
|
65
|
-
|
|
66
|
+
import_diagnostics.logger.error(error);
|
|
66
67
|
}
|
|
67
68
|
});
|
|
68
69
|
}
|
|
@@ -78,7 +79,7 @@ var Hmr = class {
|
|
|
78
79
|
runtimeParams
|
|
79
80
|
} = moduleDefinition;
|
|
80
81
|
const {format, debug, compat} = runtimeEnvironment;
|
|
81
|
-
|
|
82
|
+
import_diagnostics.logger.info(`Recompiled module: ${specifier}, ${signature}`);
|
|
82
83
|
const moduleId = {
|
|
83
84
|
specifier,
|
|
84
85
|
namespace,
|
|
@@ -106,7 +107,7 @@ var Hmr = class {
|
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
109
|
updateTemplateOnClients(compiledView) {
|
|
109
|
-
|
|
110
|
+
import_diagnostics.logger.info("Recompiled view source", compiledView.viewId);
|
|
110
111
|
const {contentTemplate} = compiledView.viewId;
|
|
111
112
|
if (this.connectedClients && contentTemplate) {
|
|
112
113
|
for (const ws of this.connectedClients.keys()) {
|
|
@@ -121,7 +122,7 @@ var Hmr = class {
|
|
|
121
122
|
}
|
|
122
123
|
updateAssetOnClients(asset) {
|
|
123
124
|
const assetId = asset.entry;
|
|
124
|
-
|
|
125
|
+
import_diagnostics.logger.info(`Updated asset: ${assetId}`);
|
|
125
126
|
if (this.connectedClients) {
|
|
126
127
|
for (const ws of this.connectedClients.keys()) {
|
|
127
128
|
ws.send(JSON.stringify({
|
|
@@ -11,7 +11,9 @@ __export(exports, {
|
|
|
11
11
|
localeMiddleware: () => localeMiddleware
|
|
12
12
|
});
|
|
13
13
|
function localeMiddleware(app, context) {
|
|
14
|
-
const {
|
|
14
|
+
const {
|
|
15
|
+
i18n: {defaultLocale}
|
|
16
|
+
} = context.runtimeEnvironment;
|
|
15
17
|
app.use(async (req, _res, next) => {
|
|
16
18
|
const langs = req.acceptsLanguages();
|
|
17
19
|
req.locale = langs?.length > 0 && langs[0] != "*" ? langs[0] : defaultLocale;
|
|
@@ -28,19 +28,29 @@ __export(exports, {
|
|
|
28
28
|
});
|
|
29
29
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
30
30
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
31
|
+
var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
|
|
31
32
|
var import_identity = __toModule(require("./utils/identity.cjs"));
|
|
32
33
|
var import_error_handling = __toModule(require("./utils/error-handling.cjs"));
|
|
33
34
|
function createMappingMiddleware(context) {
|
|
34
|
-
const {
|
|
35
|
+
const {
|
|
36
|
+
appConfig,
|
|
37
|
+
moduleBundler,
|
|
38
|
+
moduleRegistry,
|
|
39
|
+
runtimeEnvironment: defaultRuntimeEnvironment
|
|
40
|
+
} = context;
|
|
35
41
|
return async (req, res) => {
|
|
36
|
-
if (!req.validateEnvironmentRequest(
|
|
42
|
+
if (!req.validateEnvironmentRequest(appConfig)) {
|
|
37
43
|
res.status(400);
|
|
38
44
|
res.send(import_diagnostics.descriptions.UNRESOLVABLE.INVALID_ENVIRONMENT(req.params.environment).message);
|
|
39
45
|
return;
|
|
40
46
|
}
|
|
41
|
-
const {runtimeEnvironment, runtimeParams} = req.getRuntimeContext(
|
|
47
|
+
const {runtimeEnvironment, runtimeParams} = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
42
48
|
const {moduleIds} = (0, import_identity.getMappingIdentity)(req);
|
|
43
|
-
const importMetadata = await (0,
|
|
49
|
+
const importMetadata = await (0, import_instrumentation.getTracer)().trace({
|
|
50
|
+
name: import_instrumentation.RequestHandlerSpan.GetMapping
|
|
51
|
+
}, () => {
|
|
52
|
+
return (0, import_shared_utils.getImportMetadataMappings)(moduleIds, runtimeEnvironment, runtimeParams, moduleRegistry, moduleBundler);
|
|
53
|
+
});
|
|
44
54
|
if (req.isSiteGeneration()) {
|
|
45
55
|
res.setSiteGenerationMetadata({importMetadata});
|
|
46
56
|
}
|
|
@@ -28,15 +28,16 @@ __export(exports, {
|
|
|
28
28
|
});
|
|
29
29
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
30
30
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
31
|
+
var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
|
|
31
32
|
var import_request = __toModule(require("./utils/request.cjs"));
|
|
32
33
|
var import_identity = __toModule(require("./utils/identity.cjs"));
|
|
33
34
|
var import_unsigned_module_redirect = __toModule(require("./redirects/unsigned-module-redirect.cjs"));
|
|
34
35
|
var import_error_handling = __toModule(require("./utils/error-handling.cjs"));
|
|
35
36
|
function createModuleMiddleware(context) {
|
|
36
|
-
const {moduleRegistry} = context;
|
|
37
|
+
const {appConfig, moduleRegistry, runtimeEnvironment: defaultRuntimeEnvironment} = context;
|
|
37
38
|
const unsignedRedirect = (0, import_unsigned_module_redirect.createUnsignedModuleRedirect)(moduleRegistry);
|
|
38
39
|
return async (req, res) => {
|
|
39
|
-
if (!req.validateEnvironmentRequest(
|
|
40
|
+
if (!req.validateEnvironmentRequest(appConfig)) {
|
|
40
41
|
res.status(400);
|
|
41
42
|
res.send(import_diagnostics.descriptions.UNRESOLVABLE.INVALID_ENVIRONMENT(req.params.environment).message);
|
|
42
43
|
return;
|
|
@@ -46,14 +47,21 @@ function createModuleMiddleware(context) {
|
|
|
46
47
|
res.send(import_diagnostics.descriptions.UNRESOLVABLE.INVALID_JSON().message);
|
|
47
48
|
return;
|
|
48
49
|
}
|
|
49
|
-
const {runtimeEnvironment, runtimeParams} = req.getRuntimeContext(
|
|
50
|
+
const {runtimeEnvironment, runtimeParams} = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
50
51
|
const importer = req.query.importer ? await (0, import_request.getRequestImporter)(req, moduleRegistry, runtimeParams) : void 0;
|
|
51
52
|
const {moduleId, signature} = (0, import_identity.getModuleIdentity)(req, importer);
|
|
52
53
|
if (moduleId.importer || !signature) {
|
|
53
54
|
await unsignedRedirect(req, res, moduleId, runtimeEnvironment, runtimeParams);
|
|
54
55
|
return;
|
|
55
56
|
}
|
|
56
|
-
const moduleDefinition = await
|
|
57
|
+
const moduleDefinition = await (0, import_instrumentation.getTracer)().trace({
|
|
58
|
+
name: import_instrumentation.RequestHandlerSpan.GetModule,
|
|
59
|
+
attributes: {
|
|
60
|
+
specifier: moduleId.specifier
|
|
61
|
+
}
|
|
62
|
+
}, () => {
|
|
63
|
+
return moduleRegistry.getLinkedModule(moduleId, {...runtimeEnvironment, bundle: false}, runtimeParams);
|
|
64
|
+
});
|
|
57
65
|
const {ownHash, linkedSource} = moduleDefinition;
|
|
58
66
|
if (signature !== import_shared_utils.LATEST_SIGNATURE && ownHash !== signature) {
|
|
59
67
|
res.status(404).send(import_diagnostics.descriptions.UNRESOLVABLE.SIGNED_MODULE(moduleId.specifier, signature).message);
|
|
@@ -26,7 +26,7 @@ __markAsModule(exports);
|
|
|
26
26
|
__export(exports, {
|
|
27
27
|
requestProcessorMiddleware: () => requestProcessorMiddleware
|
|
28
28
|
});
|
|
29
|
-
var
|
|
29
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
30
30
|
var MRT_REQUEST_CLASS = "X-Mobify-Request-Class";
|
|
31
31
|
var MRT_REQUEST_CLASS_KEY = MRT_REQUEST_CLASS.toLowerCase();
|
|
32
32
|
function requestProcessorMiddleware(app, context) {
|
|
@@ -34,20 +34,20 @@ function requestProcessorMiddleware(app, context) {
|
|
|
34
34
|
app.use(async (req, _res, next) => {
|
|
35
35
|
let requestClass;
|
|
36
36
|
if (req.headers) {
|
|
37
|
-
if (
|
|
37
|
+
if (import_diagnostics.logger.currentLevel === "debug" || import_diagnostics.logger.currentLevel == "verbose") {
|
|
38
38
|
for (const headerName in req.headers) {
|
|
39
|
-
|
|
39
|
+
import_diagnostics.logger.debug(`[request-processor-middleware] Header ${headerName}: ${req.headers[headerName]}`);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
requestClass = req.headers[MRT_REQUEST_CLASS_KEY];
|
|
43
43
|
}
|
|
44
44
|
if (req.headers && typeof requestClass === "string") {
|
|
45
45
|
const parsedRequestClass = parseRequestClass(requestClass);
|
|
46
|
-
|
|
46
|
+
import_diagnostics.logger.debug(`[request-processor-middleware] parsedRequestClass?.basePath: ${parsedRequestClass?.basePath}`);
|
|
47
47
|
const pathValue = parsedRequestClass?.basePath || basePath || "";
|
|
48
48
|
req.basePath = pathValue === "" || pathValue.indexOf("/") === 0 ? pathValue : `/${pathValue}`;
|
|
49
49
|
} else {
|
|
50
|
-
|
|
50
|
+
import_diagnostics.logger.debug(`[request-processor-middleware] ${MRT_REQUEST_CLASS_KEY} ignored ${req.headers ? req.headers[MRT_REQUEST_CLASS_KEY] : "no-headers"}`);
|
|
51
51
|
req.basePath = basePath;
|
|
52
52
|
}
|
|
53
53
|
await next();
|
|
@@ -30,13 +30,13 @@ var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
|
30
30
|
var import_identity = __toModule(require("./utils/identity.cjs"));
|
|
31
31
|
var import_error_handling = __toModule(require("./utils/error-handling.cjs"));
|
|
32
32
|
function createResourceMiddleware(context) {
|
|
33
|
-
const {resourceRegistry} = context;
|
|
33
|
+
const {appConfig, resourceRegistry, runtimeEnvironment: defaultRuntimeEnvironment} = context;
|
|
34
34
|
return async (req, res) => {
|
|
35
|
-
if (!req.validateEnvironmentRequest(
|
|
35
|
+
if (!req.validateEnvironmentRequest(appConfig)) {
|
|
36
36
|
res.status(400).send(import_diagnostics.descriptions.UNRESOLVABLE.INVALID_ENVIRONMENT(req.params.environment).message);
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
|
-
const {runtimeEnvironment, runtimeParams} = req.getRuntimeContext(
|
|
39
|
+
const {runtimeEnvironment, runtimeParams} = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
40
40
|
const {resourceId} = (0, import_identity.getResourceIdentity)(req);
|
|
41
41
|
const resource = await resourceRegistry.getResource(resourceId, runtimeEnvironment, runtimeParams);
|
|
42
42
|
if (req.isSiteGeneration()) {
|
|
@@ -27,6 +27,7 @@ __export(exports, {
|
|
|
27
27
|
handleErrors: () => handleErrors
|
|
28
28
|
});
|
|
29
29
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
30
|
+
var import_diagnostics2 = __toModule(require("@lwrjs/diagnostics"));
|
|
30
31
|
function createReturnStatus(error, url) {
|
|
31
32
|
if (error instanceof import_diagnostics.LwrUnresolvableError && error.diagnostics[0].description.category === "lwrUnresolvable/invalid") {
|
|
32
33
|
return {status: 400, message: error.message};
|
|
@@ -42,11 +43,11 @@ function handleErrors(middleware) {
|
|
|
42
43
|
await middleware(req, res, next);
|
|
43
44
|
} catch (err) {
|
|
44
45
|
if (err instanceof import_diagnostics.DiagnosticsError) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
import_diagnostics2.logger.error("LWR Diagnostic Error: " + err.message);
|
|
47
|
+
import_diagnostics2.logger.error(err.diagnostics);
|
|
48
|
+
import_diagnostics2.logger.error(err.stack);
|
|
48
49
|
} else {
|
|
49
|
-
|
|
50
|
+
import_diagnostics2.logger.error(err);
|
|
50
51
|
}
|
|
51
52
|
const {status, message} = createReturnStatus(err, req.originalUrl);
|
|
52
53
|
res.status(status);
|
|
@@ -29,12 +29,15 @@ __export(exports, {
|
|
|
29
29
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
30
30
|
var import_router = __toModule(require("@lwrjs/router"));
|
|
31
31
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
32
|
+
var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
|
|
32
33
|
var import_error_handling = __toModule(require("./utils/error-handling.cjs"));
|
|
33
34
|
var import_view_registry = __toModule(require("@lwrjs/view-registry"));
|
|
34
35
|
function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
35
36
|
const errorRoute = errorRoutes.find((route2) => route2.status === 500);
|
|
37
|
+
const appConfig = context.appConfig;
|
|
38
|
+
const {environment: environmentConfig} = appConfig;
|
|
36
39
|
return async (req, res) => {
|
|
37
|
-
if (!req.validateEnvironmentRequest(
|
|
40
|
+
if (!req.validateEnvironmentRequest(appConfig)) {
|
|
38
41
|
res.status(400);
|
|
39
42
|
res.send(import_diagnostics.descriptions.UNRESOLVABLE.INVALID_ENVIRONMENT(req.params.environment).message);
|
|
40
43
|
return;
|
|
@@ -45,7 +48,6 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
|
45
48
|
return;
|
|
46
49
|
}
|
|
47
50
|
const {runtimeEnvironment, runtimeParams} = req.getRuntimeContext(context.runtimeEnvironment);
|
|
48
|
-
const {environment: environmentConfig} = context.appConfig;
|
|
49
51
|
if (!runtimeParams.environment && environmentConfig?.default) {
|
|
50
52
|
runtimeParams.environment = environmentConfig.default;
|
|
51
53
|
}
|
|
@@ -59,15 +61,29 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
|
59
61
|
let viewResponse;
|
|
60
62
|
let resolvedRoute;
|
|
61
63
|
try {
|
|
62
|
-
viewResponse = await
|
|
64
|
+
viewResponse = await (0, import_instrumentation.getTracer)().trace({
|
|
65
|
+
name: import_instrumentation.RequestHandlerSpan.GetView,
|
|
66
|
+
attributes: {
|
|
67
|
+
view: route.id
|
|
68
|
+
}
|
|
69
|
+
}, () => {
|
|
70
|
+
return resolve.call(viewHandler, viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
71
|
+
});
|
|
63
72
|
resolvedRoute = route;
|
|
64
73
|
} catch (err) {
|
|
65
74
|
if (!errorRoute) {
|
|
66
75
|
throw err;
|
|
67
76
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
viewResponse = await
|
|
77
|
+
import_diagnostics.logger.error(`[view-middleware] Route Error ${req.originalUrl}`);
|
|
78
|
+
import_diagnostics.logger.error(err);
|
|
79
|
+
viewResponse = await (0, import_instrumentation.getTracer)().trace({
|
|
80
|
+
name: import_instrumentation.RequestHandlerSpan.GetView,
|
|
81
|
+
attributes: {
|
|
82
|
+
view: errorRoute.id
|
|
83
|
+
}
|
|
84
|
+
}, () => {
|
|
85
|
+
return resolve.call(viewHandler, viewRequest, errorRoute, runtimeEnvironment, runtimeParams);
|
|
86
|
+
});
|
|
71
87
|
resolvedRoute = errorRoute;
|
|
72
88
|
}
|
|
73
89
|
if (req.isSiteGeneration()) {
|
|
@@ -142,15 +158,28 @@ function viewMiddleware(app, context) {
|
|
|
142
158
|
subRoutes.routes.forEach((subRoute) => subRoute.uri !== route.path && paths.push(`${prefix}${subRoute.uri}`));
|
|
143
159
|
}
|
|
144
160
|
if (i18n.uriPattern === "path-prefix") {
|
|
145
|
-
const
|
|
161
|
+
const defaultLocalePaths = paths.map((routePath) => `/${i18n.defaultLocale}${routePath}`);
|
|
162
|
+
const supportedStr = i18n.locales.map((l) => l.id).filter((id) => id !== i18n.defaultLocale).join("|");
|
|
146
163
|
paths.forEach((routePath) => {
|
|
147
164
|
const localizedPath = `/:locale(${supportedStr})${routePath}`;
|
|
148
|
-
import_shared_utils.logger.debug(`[view-middleware] Add localized path ${localizedPath}`);
|
|
149
165
|
paths.push(localizedPath);
|
|
150
166
|
});
|
|
167
|
+
addDefaultLocaleRedirects(i18n.defaultLocale, defaultLocalePaths, app);
|
|
151
168
|
}
|
|
169
|
+
import_diagnostics.logger.debug(`[view-middleware] Add view paths ${paths}`);
|
|
152
170
|
app.get(paths, (0, import_error_handling.handleErrors)(createViewMiddleware(route, errorRoutes, context, viewHandler)));
|
|
153
171
|
}
|
|
154
172
|
app.get((0, import_shared_utils.getClientBootstrapConfigurationRoutes)(), (0, import_error_handling.handleErrors)(createConfigMiddleware(routes, context, viewHandler)));
|
|
155
173
|
app.get("/" + app.getRegexWildcard(), (0, import_error_handling.handleErrors)(createNotFoundMiddleware(errorRoutes, context, viewHandler)));
|
|
156
174
|
}
|
|
175
|
+
function addDefaultLocaleRedirects(defaultLocale, defaultLocalePaths, app) {
|
|
176
|
+
import_diagnostics.logger.debug(`[view-middleware] Add default localized paths ${defaultLocalePaths}`);
|
|
177
|
+
app.get(defaultLocalePaths, (req, res) => {
|
|
178
|
+
let modifiedPath = req.originalUrl.replace(`/${defaultLocale}`, "");
|
|
179
|
+
if (modifiedPath.indexOf("/") !== 0) {
|
|
180
|
+
modifiedPath = `/${modifiedPath}`;
|
|
181
|
+
}
|
|
182
|
+
res.setHeader("Location", modifiedPath);
|
|
183
|
+
return res.sendStatus(301);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
@@ -30,16 +30,16 @@ var import_static_generation = __toModule(require("./static-generation.cjs"));
|
|
|
30
30
|
var import_dir = __toModule(require("./utils/dir.cjs"));
|
|
31
31
|
var import_network_dispatcher = __toModule(require("./utils/network-dispatcher.cjs"));
|
|
32
32
|
var import_config = __toModule(require("@lwrjs/config"));
|
|
33
|
-
var
|
|
33
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
34
34
|
async function warmupServer(config, internalRequestKey) {
|
|
35
|
-
if (!
|
|
36
|
-
|
|
35
|
+
if (!import_diagnostics.logger.currentLevel || import_diagnostics.logger.currentLevel == import_diagnostics.WARN || import_diagnostics.logger.currentLevel == import_diagnostics.INFO) {
|
|
36
|
+
import_diagnostics.logger.setOptions({dedupe: new Set([import_diagnostics.WARN])});
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
const {
|
|
38
|
+
import_diagnostics.logger.info("[Server Warmup] starting");
|
|
39
|
+
const {basePath, port, routes, staticSiteGenerator} = config;
|
|
40
40
|
staticSiteGenerator.outputDir = import_dir.skipDirCreation;
|
|
41
41
|
const urlRewriteMap = new Map();
|
|
42
42
|
const runtimeEnvironment = (0, import_config.getRuntimeEnvironment)(config);
|
|
43
43
|
await new import_static_generation.default().generateRoutes(runtimeEnvironment, staticSiteGenerator, routes, basePath, new import_network_dispatcher.default(port, internalRequestKey), staticSiteGenerator.outputDir, urlRewriteMap);
|
|
44
|
-
|
|
44
|
+
import_diagnostics.logger.info("[Server Warmup] complete");
|
|
45
45
|
}
|