@lwrjs/core 0.9.0-alpha.1 → 0.9.0-alpha.11
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/{hooks.cjs → configurations.cjs} +33 -9
- package/build/cjs/context/provider.cjs +82 -0
- package/build/cjs/context/server.cjs +75 -0
- package/build/cjs/context/services.cjs +8 -1
- package/build/cjs/index.cjs +39 -139
- package/build/cjs/middleware/asset-middleware.cjs +56 -0
- package/build/cjs/middleware/bundle-middleware.cjs +114 -0
- package/build/cjs/{middlewares → middleware}/hmr-middleware.cjs +4 -4
- package/build/cjs/{middlewares → middleware}/locale-middleware.cjs +2 -2
- package/build/cjs/middleware/mapping-middleware.cjs +61 -0
- package/build/cjs/middleware/module-middleware.cjs +88 -0
- package/build/cjs/middleware/redirects/unsigned-module-redirect.cjs +21 -0
- package/build/cjs/middleware/resource-middleware.cjs +64 -0
- package/build/cjs/middleware/utils/error-handling.cjs +56 -0
- package/build/cjs/middleware/utils/identity.cjs +93 -0
- package/build/cjs/middleware/utils/metadata.cjs +49 -0
- package/build/cjs/{middlewares/utils.cjs → middleware/utils/request.cjs} +17 -16
- package/build/cjs/middleware/view-middleware.cjs +154 -0
- package/build/cjs/middleware.cjs +43 -0
- package/build/cjs/tools/server-build.cjs +182 -0
- package/build/cjs/tools/static-generation.cjs +34 -24
- package/build/es/context/configurations.d.ts +9 -0
- package/build/es/context/configurations.js +53 -0
- package/build/es/context/provider.d.ts +3 -0
- package/build/es/context/provider.js +38 -0
- package/build/es/context/server.d.ts +3 -0
- package/build/es/context/server.js +48 -0
- package/build/es/context/services.d.ts +2 -7
- package/build/es/context/services.js +11 -1
- package/build/es/index.d.ts +3 -2
- package/build/es/index.js +45 -130
- package/build/es/middleware/asset-middleware.d.ts +3 -0
- package/build/es/middleware/asset-middleware.js +26 -0
- package/build/es/middleware/bundle-middleware.d.ts +3 -0
- package/build/es/middleware/bundle-middleware.js +87 -0
- package/build/es/middleware/hmr-middleware.d.ts +5 -0
- package/build/es/{middlewares → middleware}/hmr-middleware.js +2 -2
- package/build/es/middleware/locale-middleware.d.ts +3 -0
- package/build/es/{middlewares → middleware}/locale-middleware.js +2 -1
- package/build/es/middleware/mapping-middleware.d.ts +3 -0
- package/build/es/middleware/mapping-middleware.js +34 -0
- package/build/es/middleware/module-middleware.d.ts +3 -0
- package/build/es/middleware/module-middleware.js +62 -0
- package/build/es/middleware/redirects/unsigned-module-redirect.d.ts +5 -0
- package/build/es/middleware/redirects/unsigned-module-redirect.js +10 -0
- package/build/es/middleware/resource-middleware.d.ts +3 -0
- package/build/es/middleware/resource-middleware.js +37 -0
- package/build/es/middleware/utils/error-handling.d.ts +3 -0
- package/build/es/middleware/utils/error-handling.js +32 -0
- package/build/es/middleware/utils/identity.d.ts +6 -0
- package/build/es/middleware/utils/identity.js +64 -0
- package/build/es/middleware/utils/metadata.d.ts +3 -0
- package/build/es/middleware/utils/metadata.js +28 -0
- package/build/es/middleware/utils/request.d.ts +15 -0
- package/build/es/{middlewares/utils.js → middleware/utils/request.js} +15 -23
- package/build/es/middleware/view-middleware.d.ts +3 -0
- package/build/es/middleware/view-middleware.js +139 -0
- package/build/es/middleware.d.ts +9 -0
- package/build/es/middleware.js +13 -0
- package/build/es/tools/server-build.d.ts +14 -0
- package/build/es/tools/server-build.js +182 -0
- package/build/es/tools/static-generation.js +50 -34
- package/build/es/tools/types.d.ts +1 -0
- package/package.json +33 -30
- package/build/cjs/middlewares/api-middleware.cjs +0 -359
- package/build/cjs/middlewares/base-middleware.cjs +0 -15
- package/build/cjs/middlewares/ui-middleware.cjs +0 -183
- package/build/es/context/hooks.d.ts +0 -9
- package/build/es/context/hooks.js +0 -36
- package/build/es/middlewares/api-middleware.d.ts +0 -3
- package/build/es/middlewares/api-middleware.js +0 -410
- package/build/es/middlewares/base-middleware.d.ts +0 -3
- package/build/es/middlewares/base-middleware.js +0 -4
- package/build/es/middlewares/hmr-middleware.d.ts +0 -5
- package/build/es/middlewares/locale-middleware.d.ts +0 -3
- package/build/es/middlewares/ui-middleware.d.ts +0 -3
- package/build/es/middlewares/ui-middleware.js +0 -186
- package/build/es/middlewares/utils.d.ts +0 -22
|
@@ -1,183 +0,0 @@
|
|
|
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/middlewares/ui-middleware.ts
|
|
25
|
-
__markAsModule(exports);
|
|
26
|
-
__export(exports, {
|
|
27
|
-
default: () => uiMiddleware
|
|
28
|
-
});
|
|
29
|
-
var import_ms = __toModule(require("ms"));
|
|
30
|
-
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
31
|
-
var import_view_registry = __toModule(require("@lwrjs/view-registry"));
|
|
32
|
-
var import_utils = __toModule(require("./utils.cjs"));
|
|
33
|
-
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
34
|
-
var import_router = __toModule(require("@lwrjs/router"));
|
|
35
|
-
function uiMiddleware(app, context) {
|
|
36
|
-
const {viewRegistry, moduleRegistry, runtimeEnvironment: defaultRuntimeEnvironment} = context;
|
|
37
|
-
const {environment: environmentConfig, routes, errorRoutes} = context.appConfig;
|
|
38
|
-
const route404 = errorRoutes.find((r) => r.status === 404);
|
|
39
|
-
const route500 = errorRoutes.find((r) => r.status === 500);
|
|
40
|
-
const viewHandler = new import_view_registry.LwrViewHandler({viewRegistry, moduleRegistry}, context.appConfig);
|
|
41
|
-
async function sendViewResponse(req, res, route, defaultStatus = 200) {
|
|
42
|
-
if (!req.validateJsonRequest()) {
|
|
43
|
-
res.status(400).send({error: "Accept header and json query parameter are incompatible"});
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
req.params.bundleSpecifier = defaultRuntimeEnvironment.bundle ? "0" : void 0;
|
|
47
|
-
const {runtimeEnvironment, runtimeParams} = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
48
|
-
const targetEnvironment = runtimeParams.environment;
|
|
49
|
-
if (!(0, import_utils.isSupportedEnvironment)(environmentConfig, targetEnvironment)) {
|
|
50
|
-
res.status(400).send({error: `Environment "${targetEnvironment}" is not supported`});
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (!targetEnvironment && environmentConfig?.default) {
|
|
54
|
-
runtimeParams.environment = environmentConfig.default;
|
|
55
|
-
}
|
|
56
|
-
try {
|
|
57
|
-
const viewRequest = {
|
|
58
|
-
url: req.originalUrl,
|
|
59
|
-
params: req.params,
|
|
60
|
-
query: req.query,
|
|
61
|
-
requestPath: req.path
|
|
62
|
-
};
|
|
63
|
-
const response = req.isJsonRequest() ? await viewHandler.getViewJson(viewRequest, route, runtimeEnvironment, runtimeParams) : await viewHandler.getViewContent(viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
64
|
-
const cacheTtl = response.cache?.ttl || route.cache?.ttl;
|
|
65
|
-
let ttl;
|
|
66
|
-
if (cacheTtl) {
|
|
67
|
-
ttl = typeof cacheTtl === "string" ? (0, import_ms.default)(cacheTtl) / 1e3 : cacheTtl;
|
|
68
|
-
res.setHeader("Cache-control", `public, max-age=${ttl}`);
|
|
69
|
-
}
|
|
70
|
-
const headers = response.headers || {
|
|
71
|
-
"Content-Type": "text/html",
|
|
72
|
-
...cacheTtl && {"Cache-control": `public, max-age=${ttl}`}
|
|
73
|
-
};
|
|
74
|
-
res.set(headers);
|
|
75
|
-
res.setMetadata(response.metadata);
|
|
76
|
-
const status = response.status ? response.status : defaultStatus;
|
|
77
|
-
res.status(status).send(response.body);
|
|
78
|
-
} catch (error) {
|
|
79
|
-
if (error instanceof import_diagnostics.DiagnosticsError) {
|
|
80
|
-
console.error("LWR Diagnostic Error: " + error.message);
|
|
81
|
-
console.error(error.diagnostics);
|
|
82
|
-
console.error(error.stack);
|
|
83
|
-
} else {
|
|
84
|
-
console.error(error);
|
|
85
|
-
}
|
|
86
|
-
if (route500 && defaultStatus !== 500) {
|
|
87
|
-
await sendViewResponse(req, res, route500, 500);
|
|
88
|
-
} else {
|
|
89
|
-
res.status(500).send(`500 - Error retrieving view for route "${route.id}"`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
async function sendConfigurationResponse(req, res, defaultStatus = 200) {
|
|
94
|
-
req.params.bundleSpecifier = defaultRuntimeEnvironment.bundle ? "0" : void 0;
|
|
95
|
-
const {runtimeEnvironment, runtimeParams} = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
96
|
-
const {appId, encodedViewPath} = req.params;
|
|
97
|
-
const route = routes.find((route2) => route2.id === appId);
|
|
98
|
-
if (!route) {
|
|
99
|
-
res.status(404).send({error: `LWR configuration for appId "${appId}" is not available`});
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
try {
|
|
103
|
-
const url = (0, import_shared_utils.decodeViewPath)(encodedViewPath);
|
|
104
|
-
const requestPath = route.path;
|
|
105
|
-
const params = (0, import_shared_utils.extractRequestParams)(requestPath, url, req.params);
|
|
106
|
-
const viewRequest = {
|
|
107
|
-
url,
|
|
108
|
-
params,
|
|
109
|
-
query: req.query,
|
|
110
|
-
requestPath
|
|
111
|
-
};
|
|
112
|
-
const response = await viewHandler.getViewConfiguration(viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
113
|
-
if (!response) {
|
|
114
|
-
res.status(404).send({error: `LWR configuration for viewPath "${url}" is not available`});
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
const cacheTtl = response.cache?.ttl || route.cache?.ttl;
|
|
118
|
-
let ttl;
|
|
119
|
-
if (cacheTtl) {
|
|
120
|
-
ttl = typeof cacheTtl === "string" ? (0, import_ms.default)(cacheTtl) / 1e3 : cacheTtl;
|
|
121
|
-
}
|
|
122
|
-
res.set({
|
|
123
|
-
"Content-Type": "application/javascript",
|
|
124
|
-
...cacheTtl && {"Cache-control": `public, max-age=${ttl}`}
|
|
125
|
-
});
|
|
126
|
-
const status = response.status ? response.status : defaultStatus;
|
|
127
|
-
res.status(status).send(response.body);
|
|
128
|
-
} catch (error) {
|
|
129
|
-
if (error instanceof import_diagnostics.DiagnosticsError) {
|
|
130
|
-
console.error("LWR Diagnostic Error: " + error.message);
|
|
131
|
-
console.error(error.diagnostics);
|
|
132
|
-
console.error(error.stack);
|
|
133
|
-
} else {
|
|
134
|
-
console.error(error);
|
|
135
|
-
}
|
|
136
|
-
if (route500 && defaultStatus !== 500) {
|
|
137
|
-
await sendViewResponse(req, res, route500, 500);
|
|
138
|
-
} else {
|
|
139
|
-
res.status(500).send(`500 - Error retrieving route "${route.id}"`);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
routes.forEach((route) => {
|
|
144
|
-
if (route.method === "post") {
|
|
145
|
-
app.post(route.path, async (req, res) => {
|
|
146
|
-
await sendViewResponse(req, res, route);
|
|
147
|
-
});
|
|
148
|
-
} else {
|
|
149
|
-
const serverPath = route.path;
|
|
150
|
-
const paths = [serverPath];
|
|
151
|
-
const subRoutes = route.subRoutes ? (0, import_router.getClientRoutes)(route.subRoutes) : void 0;
|
|
152
|
-
if (subRoutes) {
|
|
153
|
-
const prefix = serverPath === "/" ? "" : serverPath;
|
|
154
|
-
subRoutes.routes.forEach((r) => paths.push(`${prefix}${r.uri}`));
|
|
155
|
-
}
|
|
156
|
-
paths.forEach((path) => {
|
|
157
|
-
app.get(path, async (req, res) => {
|
|
158
|
-
await sendViewResponse(req, res, route);
|
|
159
|
-
});
|
|
160
|
-
app.get([
|
|
161
|
-
`/:apiVersion/application/:format/l/:locale/ai/:appId${path}`,
|
|
162
|
-
`/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId${path}`,
|
|
163
|
-
`/:apiVersion/application/:format/ai/:appId${path}`,
|
|
164
|
-
`/:apiVersion/application/:format/e/:environment/ai/:appId${path}`
|
|
165
|
-
], async (req, res) => {
|
|
166
|
-
await sendViewResponse(req, res, route);
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
const clientBootstrapConfigurationRoutes = (0, import_shared_utils.getClientBootstrapConfigurationRoutes)();
|
|
172
|
-
app.get(clientBootstrapConfigurationRoutes, async (req, res) => {
|
|
173
|
-
await sendConfigurationResponse(req, res);
|
|
174
|
-
});
|
|
175
|
-
app.initRoutes();
|
|
176
|
-
app.use(async (req, res) => {
|
|
177
|
-
if (route404) {
|
|
178
|
-
await sendViewResponse(req, res, route404, 404);
|
|
179
|
-
} else {
|
|
180
|
-
res.status(404).send("404 - This page does not exist");
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { NormalizedLwrGlobalConfig, RuntimeEnvironment, GlobalData, HooksPlugin } from '@lwrjs/types';
|
|
2
|
-
interface Configurations {
|
|
3
|
-
lwrConfig: NormalizedLwrGlobalConfig;
|
|
4
|
-
dataConfig: GlobalData;
|
|
5
|
-
runtimeConfig: RuntimeEnvironment;
|
|
6
|
-
}
|
|
7
|
-
export declare function runConfigurationsHook(hookPlugins: HooksPlugin[], lwrConfig: NormalizedLwrGlobalConfig, dataConfig: GlobalData, runtimeConfig: RuntimeEnvironment): Promise<Configurations>;
|
|
8
|
-
export {};
|
|
9
|
-
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_LWR_BOOTSTRAP_CONFIG, logger } from '@lwrjs/shared-utils';
|
|
2
|
-
import { validateLwrAppConfig } from '@lwrjs/config';
|
|
3
|
-
// Add missing bootstrap objects to routes
|
|
4
|
-
function normalizeRoutesBootstrap({ routes, errorRoutes }) {
|
|
5
|
-
[...routes, ...errorRoutes].forEach((route) => {
|
|
6
|
-
if (!route.bootstrap) {
|
|
7
|
-
route.bootstrap = { ...DEFAULT_LWR_BOOTSTRAP_CONFIG };
|
|
8
|
-
}
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
export async function runConfigurationsHook(hookPlugins, lwrConfig, dataConfig, runtimeConfig) {
|
|
12
|
-
for (const hookPlugin of hookPlugins) {
|
|
13
|
-
// eslint-disable-next-line no-await-in-loop
|
|
14
|
-
await hookPlugin.initConfigs(lwrConfig, dataConfig, runtimeConfig);
|
|
15
|
-
}
|
|
16
|
-
try {
|
|
17
|
-
validateLwrAppConfig(JSON.stringify(lwrConfig), 'post');
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
// TODO: temporary workaround for https://github.com/salesforce/lwr/issues/825
|
|
21
|
-
if (process.env.UNSAFE_IGNORE_CONFIG_VALIDATION === 'true') {
|
|
22
|
-
logger.warn('ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution');
|
|
23
|
-
console.dir(e, { depth: null });
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
throw e;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
normalizeRoutesBootstrap(lwrConfig);
|
|
30
|
-
return {
|
|
31
|
-
lwrConfig,
|
|
32
|
-
dataConfig,
|
|
33
|
-
runtimeConfig,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=hooks.js.map
|
|
@@ -1,410 +0,0 @@
|
|
|
1
|
-
import { createReturnStatus, LwrUnresolvableError, createSingleDiagnosticError as createDiagnostic, descriptions, } from '@lwrjs/diagnostics';
|
|
2
|
-
import { LATEST_SIGNATURE, explodeSpecifier, getImportMetadataMappings, serializeModuleToJson, getModuleIdentity, getResourceIdentity, getAssetIdentity, getMappingIdentity, getVersionedModuleId, } from '@lwrjs/shared-utils';
|
|
3
|
-
import { isSupportedEnvironment } from './utils.js';
|
|
4
|
-
export default function apiMiddleware(app, context) {
|
|
5
|
-
const { appConfig: { environment: environmentConfig }, moduleRegistry, moduleBundler, resourceRegistry, runtimeEnvironment: defaultRuntimeEnvironment, } = context;
|
|
6
|
-
const errors = descriptions.UNRESOLVABLE;
|
|
7
|
-
// Bundle APIs
|
|
8
|
-
// {apiversion}/bundle/{format}/{compat}/bi/{bundlingId}-{bundlingSet}/module/mi/{specifier}/s/{signature}?{modifiers}
|
|
9
|
-
app.get([
|
|
10
|
-
// Full URL
|
|
11
|
-
`/:apiVersion/bundle/:format/:compat?/l/:locale/e/:environment/bi/:bundleSpecifier/module/mi/:specifier/latest/:prettyUrl?`,
|
|
12
|
-
`/:apiVersion/bundle/:format/:compat?/l/:locale/e/:environment/bi/:bundleSpecifier/module/mi/:specifier/s/:signature/:prettyUrl?`,
|
|
13
|
-
// Without Environment
|
|
14
|
-
`/:apiVersion/bundle/:format/:compat?/l/:locale/bi/:bundleSpecifier/module/mi/:specifier/latest/:prettyUrl?`,
|
|
15
|
-
`/:apiVersion/bundle/:format/:compat?/l/:locale/bi/:bundleSpecifier/module/mi/:specifier/s/:signature/:prettyUrl?`,
|
|
16
|
-
// Without Locale
|
|
17
|
-
`/:apiVersion/bundle/:format/:compat?/e/:environment/bi/:bundleSpecifier/module/mi/:specifier/latest/:prettyUrl?`,
|
|
18
|
-
`/:apiVersion/bundle/:format/:compat?/e/:environment/bi/:bundleSpecifier/module/mi/:specifier/s/:signature/:prettyUrl?`,
|
|
19
|
-
// Without Optional Segments
|
|
20
|
-
`/:apiVersion/bundle/:format/:compat?/bi/:bundleSpecifier/module/mi/:specifier/latest/:prettyUrl?`,
|
|
21
|
-
`/:apiVersion/bundle/:format/:compat?/bi/:bundleSpecifier/module/mi/:specifier/s/:signature/:prettyUrl?`,
|
|
22
|
-
], async (req, res) => {
|
|
23
|
-
const runtimeContext = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
24
|
-
const { runtimeEnvironment, runtimeParams } = runtimeContext;
|
|
25
|
-
const targetEnvironment = runtimeParams.environment;
|
|
26
|
-
if (!isSupportedEnvironment(environmentConfig, targetEnvironment)) {
|
|
27
|
-
res.status(400).send({ error: `Environment "${targetEnvironment}" is not supported` });
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
let moduleId, signature;
|
|
31
|
-
try {
|
|
32
|
-
({ moduleId, signature } = getModuleIdentity(req));
|
|
33
|
-
const sourceMapUrl = req.path.replace('/bundle/', '/sourcemaps/bundle/');
|
|
34
|
-
const sourceMapRuntimeContext = { ...runtimeEnvironment, sourceMapUrl };
|
|
35
|
-
// Redirect module requests to the concrete URL when requested with an importer
|
|
36
|
-
const importerSpecifier = req.query.importer;
|
|
37
|
-
if (importerSpecifier) {
|
|
38
|
-
// Get the importer's file path entry
|
|
39
|
-
const importerModuleId = explodeSpecifier(importerSpecifier);
|
|
40
|
-
const { entry } = await moduleRegistry.getModuleEntry(importerModuleId);
|
|
41
|
-
const versionedModuleEntry = await moduleRegistry.getModuleEntry({
|
|
42
|
-
...moduleId,
|
|
43
|
-
importer: entry,
|
|
44
|
-
});
|
|
45
|
-
const uri = await moduleRegistry.resolveModuleUri({ ...moduleId, version: versionedModuleEntry.version }, runtimeEnvironment, runtimeParams);
|
|
46
|
-
res.set({
|
|
47
|
-
// This redirects to a signed URI
|
|
48
|
-
// A prettifier is added to the end so resources have a meaningful name in browser devtools
|
|
49
|
-
Location: uri,
|
|
50
|
-
});
|
|
51
|
-
res.sendStatus(302);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const bundleDef = await moduleBundler.getModuleBundle(moduleId, sourceMapRuntimeContext, runtimeParams);
|
|
55
|
-
if (signature !== LATEST_SIGNATURE) {
|
|
56
|
-
res.setHeader('Cache-control', 'public, max-age=31536000, immutable');
|
|
57
|
-
}
|
|
58
|
-
// URIs for generate site
|
|
59
|
-
const resolvedUris = [];
|
|
60
|
-
if (req.isSiteGeneration()) {
|
|
61
|
-
// TODO might be able to remove this in the future but not sure how to properly send
|
|
62
|
-
// back bundleRecord imports with absolute uris (lwc is the main one)
|
|
63
|
-
if (bundleDef.bundleRecord.imports) {
|
|
64
|
-
for (const theImport of bundleDef.bundleRecord.imports) {
|
|
65
|
-
const childSpecifier = theImport.specifier;
|
|
66
|
-
// eslint-disable-next-line no-await-in-loop
|
|
67
|
-
const id = await getVersionedModuleId(childSpecifier, moduleRegistry);
|
|
68
|
-
// eslint-disable-next-line no-await-in-loop
|
|
69
|
-
const uri = await moduleRegistry.resolveModuleUri(id, runtimeEnvironment, runtimeParams);
|
|
70
|
-
resolvedUris.push(uri);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (bundleDef.bundleRecord.dynamicImports) {
|
|
74
|
-
for (const theImport of bundleDef.bundleRecord.dynamicImports) {
|
|
75
|
-
const childSpecifier = theImport.specifier;
|
|
76
|
-
// eslint-disable-next-line no-await-in-loop
|
|
77
|
-
const id = await getVersionedModuleId(childSpecifier, moduleRegistry);
|
|
78
|
-
// eslint-disable-next-line no-await-in-loop
|
|
79
|
-
const uri = await moduleRegistry.resolveModuleUri(id, runtimeEnvironment, runtimeParams);
|
|
80
|
-
resolvedUris.push(uri);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
res.setMetadata({ moduleDefinition: bundleDef, resolvedUris });
|
|
85
|
-
res.type('application/javascript').send(bundleDef.code);
|
|
86
|
-
}
|
|
87
|
-
catch (e) {
|
|
88
|
-
console.log(e);
|
|
89
|
-
const error = createReturnStatus(`bundle for "${moduleId?.specifier || req.params?.specifier}"`, e);
|
|
90
|
-
res.status(error.status).type('text/plain').send(error.message);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
// Unsigned Bundles => 302
|
|
94
|
-
app.get([
|
|
95
|
-
// Full URL
|
|
96
|
-
`/:apiVersion/bundle/:format/:compat?/l/:locale/e/:environment/bi/:bundleSpecifier/module/mi/:specifier`,
|
|
97
|
-
// Without Environment
|
|
98
|
-
`/:apiVersion/bundle/:format/:compat?/l/:locale/bi/:bundleSpecifier/module/mi/:specifier`,
|
|
99
|
-
// Without Locale
|
|
100
|
-
`/:apiVersion/bundle/:format/:compat?/e/:environment/bi/:bundleSpecifier/module/mi/:specifier`,
|
|
101
|
-
// Without Optional Segments
|
|
102
|
-
`/:apiVersion/bundle/:format/:compat?/bi/:bundleSpecifier/module/mi/:specifier`,
|
|
103
|
-
], async (req, res) => {
|
|
104
|
-
const ctx = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
105
|
-
const targetEnvironment = ctx.runtimeParams.environment;
|
|
106
|
-
if (!isSupportedEnvironment(environmentConfig, targetEnvironment)) {
|
|
107
|
-
res.status(400).send({ error: `Environment "${targetEnvironment}" is not supported` });
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
let moduleId;
|
|
111
|
-
try {
|
|
112
|
-
({ moduleId } = getModuleIdentity(req));
|
|
113
|
-
// Get the importer's specifier via the "importer" query param
|
|
114
|
-
const importerSpecifier = req.query.importer;
|
|
115
|
-
if (importerSpecifier) {
|
|
116
|
-
// Get the importer's file path entry
|
|
117
|
-
const importerModuleId = explodeSpecifier(importerSpecifier);
|
|
118
|
-
const { entry } = await moduleRegistry.getModuleEntry(importerModuleId);
|
|
119
|
-
moduleId = { ...moduleId, importer: entry };
|
|
120
|
-
}
|
|
121
|
-
const { ownHash, moduleEntry } = await moduleRegistry.getModule(moduleId, ctx.runtimeParams);
|
|
122
|
-
if (ownHash) {
|
|
123
|
-
const jsonQuery = req.isJsonRequest()
|
|
124
|
-
? `${ctx.runtimeEnvironment.debug ? '&' : '?'}json`
|
|
125
|
-
: '';
|
|
126
|
-
const uri = await moduleRegistry.resolveModuleUri({ ...moduleId, version: moduleEntry.version }, ctx.runtimeEnvironment, ctx.runtimeParams, ownHash);
|
|
127
|
-
res.set({
|
|
128
|
-
// This redirects to a signed URI
|
|
129
|
-
Location: `${uri}${jsonQuery}`,
|
|
130
|
-
});
|
|
131
|
-
res.sendStatus(302);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
catch (e) {
|
|
135
|
-
console.log(e);
|
|
136
|
-
const error = createReturnStatus(`bundle for "${moduleId?.specifier || req.params?.specifier}"`, e);
|
|
137
|
-
res.status(error.status).type('text/plain').send(error.message);
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
// Bundle sourcemaps
|
|
141
|
-
app.get([
|
|
142
|
-
// Full URL
|
|
143
|
-
`/:apiVersion/sourcemaps/bundle/:format/:compat?/l/:locale/e/:environment/bi/:bundleSpecifier/module/mi/:specifier/latest/:prettyUrl?`,
|
|
144
|
-
`/:apiVersion/sourcemaps/bundle/:format/:compat?/l/:locale/e/:environment/bi/:bundleSpecifier/module/mi/:specifier/s/:signature/:prettyUrl?`,
|
|
145
|
-
// Without Environment
|
|
146
|
-
`/:apiVersion/sourcemaps/bundle/:format/:compat?/l/:locale/bi/:bundleSpecifier/module/mi/:specifier/latest/:prettyUrl?`,
|
|
147
|
-
`/:apiVersion/sourcemaps/bundle/:format/:compat?/l/:locale/bi/:bundleSpecifier/module/mi/:specifier/s/:signature/:prettyUrl?`,
|
|
148
|
-
// Without Locale
|
|
149
|
-
`/:apiVersion/sourcemaps/bundle/:format/:compat?/e/:environment/bi/:bundleSpecifier/module/mi/:specifier/latest/:prettyUrl?`,
|
|
150
|
-
`/:apiVersion/sourcemaps/bundle/:format/:compat?/e/:environment/bi/:bundleSpecifier/module/mi/:specifier/s/:signature/:prettyUrl?`,
|
|
151
|
-
// Without Optional Segments
|
|
152
|
-
`/:apiVersion/sourcemaps/bundle/:format/:compat?/bi/:bundleSpecifier/module/mi/:specifier/latest/:prettyUrl?`,
|
|
153
|
-
`/:apiVersion/sourcemaps/bundle/:format/:compat?/bi/:bundleSpecifier/module/mi/:specifier/s/:signature/:prettyUrl?`,
|
|
154
|
-
], async (req, res) => {
|
|
155
|
-
const runtimeContext = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
156
|
-
const { runtimeParams, runtimeEnvironment } = runtimeContext;
|
|
157
|
-
const targetEnvironment = runtimeParams.environment;
|
|
158
|
-
if (!isSupportedEnvironment(environmentConfig, targetEnvironment)) {
|
|
159
|
-
res.status(400).send({ error: `Environment "${targetEnvironment}" is not supported` });
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
let moduleId, signature;
|
|
163
|
-
try {
|
|
164
|
-
({ moduleId, signature } = getModuleIdentity(req));
|
|
165
|
-
const bundleDef = await moduleBundler.getModuleBundle(moduleId, runtimeEnvironment);
|
|
166
|
-
if (signature !== LATEST_SIGNATURE) {
|
|
167
|
-
res.setHeader('Cache-control', 'public, max-age=31536000, immutable');
|
|
168
|
-
}
|
|
169
|
-
res.type('application/json').send(bundleDef.map);
|
|
170
|
-
}
|
|
171
|
-
catch (e) {
|
|
172
|
-
console.log(e);
|
|
173
|
-
const error = createReturnStatus(`bundle sourcemap for "${moduleId?.specifier || req.params?.specifier}"`, e);
|
|
174
|
-
res.status(error.status).type('text/plain').send(error.message);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
// Signed Modules
|
|
178
|
-
// /{apiversion}/module/{format}/{compat}/l/{language}/mi/{specifier}/s/{signature}
|
|
179
|
-
app.get([
|
|
180
|
-
// Full URL
|
|
181
|
-
`/:apiVersion/module/:format/:compat/l/:locale/e/:environment/mi/:specifier/latest/:prettyUrl?`,
|
|
182
|
-
`/:apiVersion/module/:format/:compat/l/:locale/e/:environment/mi/:specifier/s/:signature/:prettyUrl?`,
|
|
183
|
-
// Without Environment
|
|
184
|
-
`/:apiVersion/module/:format/:compat/l/:locale/mi/:specifier/latest/:prettyUrl?`,
|
|
185
|
-
`/:apiVersion/module/:format/:compat/l/:locale/mi/:specifier/s/:signature/:prettyUrl?`,
|
|
186
|
-
// Without Locale
|
|
187
|
-
`/:apiVersion/module/:format/:compat/e/:environment/mi/:specifier/latest/:prettyUrl?`,
|
|
188
|
-
`/:apiVersion/module/:format/:compat/e/:environment/mi/:specifier/s/:signature/:prettyUrl?`,
|
|
189
|
-
// Without Optional Segments
|
|
190
|
-
`/:apiVersion/module/:format/:compat/mi/:specifier/latest/:prettyUrl?`,
|
|
191
|
-
`/:apiVersion/module/:format/:compat/mi/:specifier/s/:signature/:prettyUrl?`,
|
|
192
|
-
], async (req, res) => {
|
|
193
|
-
const { runtimeEnvironment, runtimeParams } = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
194
|
-
const targetEnvironment = runtimeParams.environment;
|
|
195
|
-
if (!isSupportedEnvironment(environmentConfig, targetEnvironment)) {
|
|
196
|
-
res.status(400).send({ error: `Environment "${targetEnvironment}" is not supported` });
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
let moduleId, signature;
|
|
200
|
-
try {
|
|
201
|
-
({ moduleId, signature } = getModuleIdentity(req));
|
|
202
|
-
if (!req.validateJsonRequest()) {
|
|
203
|
-
throw createDiagnostic({ description: errors.INVALID_JSON() }, LwrUnresolvableError);
|
|
204
|
-
}
|
|
205
|
-
// retrieve the latest module
|
|
206
|
-
const theModule = await moduleRegistry.getLinkedModule(moduleId, runtimeEnvironment, runtimeParams);
|
|
207
|
-
const { ownHash, linkedSource } = theModule;
|
|
208
|
-
// validate the requested instances exists
|
|
209
|
-
if (signature === LATEST_SIGNATURE || ownHash === signature) {
|
|
210
|
-
const code = linkedSource;
|
|
211
|
-
res.setMetadata({ moduleDefinition: theModule });
|
|
212
|
-
if (req.isJsonRequest()) {
|
|
213
|
-
const json = await serializeModuleToJson(code, theModule, moduleRegistry, runtimeParams);
|
|
214
|
-
res.type('application/json').send(json);
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
res.type('application/javascript').send(code);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
throw createDiagnostic({ description: errors.SIGNED_MODULE(moduleId.specifier, signature) }, LwrUnresolvableError);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
catch (e) {
|
|
225
|
-
console.log(e);
|
|
226
|
-
const error = createReturnStatus(`module "${moduleId?.specifier || req.params?.specifier}"`, e);
|
|
227
|
-
res.status(error.status).type('text/plain').send(error.message);
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
// Unsigned Modules => 302
|
|
231
|
-
app.get([
|
|
232
|
-
// Full URL
|
|
233
|
-
`/:apiVersion/module/:format/:compat/l/:locale/e/:environment/mi/:specifier`,
|
|
234
|
-
// Without Environment
|
|
235
|
-
`/:apiVersion/module/:format/:compat/l/:locale/mi/:specifier`,
|
|
236
|
-
// Without Locale
|
|
237
|
-
`/:apiVersion/module/:format/:compat/e/:environment/mi/:specifier`,
|
|
238
|
-
// Without Optional Segments
|
|
239
|
-
`/:apiVersion/module/:format/:compat/mi/:specifier`,
|
|
240
|
-
], async (req, res) => {
|
|
241
|
-
const ctx = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
242
|
-
const targetEnvironment = ctx.runtimeParams.environment;
|
|
243
|
-
if (!isSupportedEnvironment(environmentConfig, targetEnvironment)) {
|
|
244
|
-
res.status(400).send({ error: `Environment "${targetEnvironment}" is not supported` });
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
let moduleId;
|
|
248
|
-
try {
|
|
249
|
-
({ moduleId } = getModuleIdentity(req));
|
|
250
|
-
// Get the importer's specifier via the "importer" query param
|
|
251
|
-
const importerSpecifier = req.query.importer;
|
|
252
|
-
if (importerSpecifier) {
|
|
253
|
-
// Get the importer's file path entry
|
|
254
|
-
const importerModuleId = explodeSpecifier(importerSpecifier);
|
|
255
|
-
const { entry } = await moduleRegistry.getModuleEntry(importerModuleId);
|
|
256
|
-
moduleId = { ...moduleId, importer: entry };
|
|
257
|
-
}
|
|
258
|
-
// Get the module's signature from the registry
|
|
259
|
-
const { ownHash, moduleEntry } = await moduleRegistry.getModule(moduleId, ctx.runtimeParams);
|
|
260
|
-
if (ownHash) {
|
|
261
|
-
const jsonQuery = req.isJsonRequest()
|
|
262
|
-
? `${ctx.runtimeEnvironment.debug ? '&' : '?'}json`
|
|
263
|
-
: '';
|
|
264
|
-
const uri = await moduleRegistry.resolveModuleUri({ ...moduleId, version: moduleEntry.version }, ctx.runtimeEnvironment, ctx.runtimeParams, ownHash);
|
|
265
|
-
res.set({
|
|
266
|
-
// This redirects to a signed URI
|
|
267
|
-
Location: `${uri}${jsonQuery}`,
|
|
268
|
-
});
|
|
269
|
-
res.sendStatus(302);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
catch (e) {
|
|
273
|
-
console.log(e);
|
|
274
|
-
const error = createReturnStatus(`module "${moduleId?.specifier || req.params?.specifier}"`, e);
|
|
275
|
-
res.status(error.status).type('text/plain').send(error.message);
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
// Mapping Services
|
|
279
|
-
// /{apiversion}/mapping/{format}/{compat}(/l/{language})?(/e/{environment})?(/bi/{bundleStrategyId})?/mp/{specifiers}
|
|
280
|
-
app.get([
|
|
281
|
-
// Full URL (3 optional segments)
|
|
282
|
-
`/:apiVersion/mapping/:format/:compat/l/:locale/e/:environment/bi/:bundleSpecifier/mp/:specifiers`,
|
|
283
|
-
// With 2 optional segments: l & e, l & bi, e & bi
|
|
284
|
-
`/:apiVersion/mapping/:format/:compat/l/:locale/e/:environment/mp/:specifiers`,
|
|
285
|
-
`/:apiVersion/mapping/:format/:compat/l/:locale/bi/:bundleSpecifier/mp/:specifiers`,
|
|
286
|
-
`/:apiVersion/mapping/:format/:compat/e/:environment/bi/:bundleSpecifier/mp/:specifiers`,
|
|
287
|
-
// With 1 optional segment
|
|
288
|
-
`/:apiVersion/mapping/:format/:compat/l/:locale/mp/:specifiers`,
|
|
289
|
-
`/:apiVersion/mapping/:format/:compat/e/:environment/mp/:specifiers`,
|
|
290
|
-
`/:apiVersion/mapping/:format/:compat/bi/:bundleSpecifier/mp/:specifiers`,
|
|
291
|
-
// With 0 optional segments
|
|
292
|
-
`/:apiVersion/mapping/:format/:compat/mp/:specifiers`,
|
|
293
|
-
], async (req, res) => {
|
|
294
|
-
const requestContext = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
295
|
-
const targetEnvironment = requestContext.runtimeParams.environment;
|
|
296
|
-
if (!isSupportedEnvironment(environmentConfig, targetEnvironment)) {
|
|
297
|
-
res.status(400).send({ error: `Environment "${targetEnvironment}" is not supported` });
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
let moduleIds;
|
|
301
|
-
try {
|
|
302
|
-
({ moduleIds } = getMappingIdentity(req));
|
|
303
|
-
const { runtimeEnvironment, runtimeParams } = requestContext;
|
|
304
|
-
const importMetadata = await getImportMetadataMappings(moduleIds, runtimeEnvironment, runtimeParams, moduleRegistry, moduleBundler);
|
|
305
|
-
// Include import metadata as an object for use with the static site generator
|
|
306
|
-
res.setMetadata({ importMetadata });
|
|
307
|
-
// Respond to request
|
|
308
|
-
res.status(200).type('application/json').send(importMetadata);
|
|
309
|
-
}
|
|
310
|
-
catch (e) {
|
|
311
|
-
console.log(e);
|
|
312
|
-
const error = createReturnStatus(`mappings for "${JSON.stringify(moduleIds || req.params?.specifiers)}"`, e);
|
|
313
|
-
res.status(error.status).send(error.message);
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
// Resources
|
|
317
|
-
app.get([
|
|
318
|
-
// Full URL
|
|
319
|
-
`/:apiVersion/resource/:format/l/:locale/e/:environment/:specifier`,
|
|
320
|
-
// Without Environment
|
|
321
|
-
`/:apiVersion/resource/:format/l/:locale/:specifier`,
|
|
322
|
-
// Without Locale
|
|
323
|
-
`/:apiVersion/resource/:format/e/:environment/:specifier`,
|
|
324
|
-
// Without Optional Segments
|
|
325
|
-
`/:apiVersion/resource/:format/:specifier`,
|
|
326
|
-
], async (req, res) => {
|
|
327
|
-
const { runtimeEnvironment, runtimeParams } = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
328
|
-
const targetEnvironment = runtimeParams.environment;
|
|
329
|
-
if (!isSupportedEnvironment(environmentConfig, targetEnvironment)) {
|
|
330
|
-
res.status(400).send({ error: `Environment "${targetEnvironment}" is not supported` });
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
let resourceId;
|
|
334
|
-
try {
|
|
335
|
-
({ resourceId } = getResourceIdentity(req));
|
|
336
|
-
const resource = await resourceRegistry.getResource(resourceId, runtimeEnvironment, runtimeParams);
|
|
337
|
-
if (resource && resource.content) {
|
|
338
|
-
// Static resource
|
|
339
|
-
const type = resource.type === 'text/css' ? resource.type : 'application/javascript';
|
|
340
|
-
res.type(type).send(resource.content);
|
|
341
|
-
}
|
|
342
|
-
else if (resource && resource.stream) {
|
|
343
|
-
// Stream-able resource
|
|
344
|
-
res.type(resource.type).stream(resource.stream);
|
|
345
|
-
}
|
|
346
|
-
else {
|
|
347
|
-
throw createDiagnostic({ description: errors.RESOURCE(resourceId.specifier) }, LwrUnresolvableError);
|
|
348
|
-
}
|
|
349
|
-
res.setMetadata({ resource });
|
|
350
|
-
}
|
|
351
|
-
catch (e) {
|
|
352
|
-
console.log(e);
|
|
353
|
-
const error = createReturnStatus(`resource "${resourceId?.specifier || req.params?.specifier}"`, e);
|
|
354
|
-
res.status(error.status).type('text/plain').send(error.message);
|
|
355
|
-
}
|
|
356
|
-
});
|
|
357
|
-
// -- Asset configuration -----------------------------------------------------------
|
|
358
|
-
// Custom defined assets
|
|
359
|
-
const paths = context.appConfig.assets.map((a) => a.urlPath);
|
|
360
|
-
// Workaround: https://github.com/pillarjs/path-to-regexp#compatibility-with-express--4x
|
|
361
|
-
// Koa routing (Path-To-RegExp) breaks compatibility with Express routing & asterisk wildcards
|
|
362
|
-
for (let i = 0; i < paths.length; i++) {
|
|
363
|
-
paths[i] = paths[i] + app.getRegexWildcard();
|
|
364
|
-
}
|
|
365
|
-
app.all(paths, async (req, res) => {
|
|
366
|
-
const { runtimeEnvironment } = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
367
|
-
try {
|
|
368
|
-
const { assetId: { specifier, type }, signature, } = getAssetIdentity(req);
|
|
369
|
-
const assetObj = await context.assetRegistry.getAsset({ specifier, signature, type }, runtimeEnvironment);
|
|
370
|
-
if (assetObj.mime) {
|
|
371
|
-
res.type(assetObj.mime);
|
|
372
|
-
}
|
|
373
|
-
res.setMetadata({ asset: assetObj });
|
|
374
|
-
res.stream(assetObj.stream());
|
|
375
|
-
}
|
|
376
|
-
catch (e) {
|
|
377
|
-
console.log(e);
|
|
378
|
-
const error = createReturnStatus(`asset at "${req.originalUrl}"`, e);
|
|
379
|
-
res.status(error.status).send(error.message);
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
// LWR specific assets
|
|
383
|
-
// Workaround: https://github.com/pillarjs/path-to-regexp#compatibility-with-express--4x
|
|
384
|
-
// Koa routing (Path-To-RegExp) breaks compatibility with Express routing & asterisk wildcards
|
|
385
|
-
app.all('/:apiVersion/:assetType/:immutable?/s/:signature/' + app.getRegexWildcard(), async (req, res) => {
|
|
386
|
-
const { runtimeEnvironment } = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
387
|
-
const { basePath } = runtimeEnvironment;
|
|
388
|
-
const { signature } = req.params;
|
|
389
|
-
const { immutable, assetType: type } = req.params;
|
|
390
|
-
const specifier = req.params[0] ? `/${req.params[0]}` : req.originalUrl;
|
|
391
|
-
const basePathSpecifier = `${basePath}${specifier}`;
|
|
392
|
-
try {
|
|
393
|
-
const assetObj = await context.assetRegistry.getAsset({ specifier: basePathSpecifier, signature, type: type }, runtimeEnvironment, req.isSiteGeneration());
|
|
394
|
-
if (immutable) {
|
|
395
|
-
// WIP: ?
|
|
396
|
-
}
|
|
397
|
-
if (assetObj.mime) {
|
|
398
|
-
res.type(assetObj.mime);
|
|
399
|
-
}
|
|
400
|
-
res.setMetadata({ asset: assetObj });
|
|
401
|
-
res.stream(assetObj.stream());
|
|
402
|
-
}
|
|
403
|
-
catch (e) {
|
|
404
|
-
console.log(e);
|
|
405
|
-
const error = createReturnStatus(`asset at "${specifier}"`, e);
|
|
406
|
-
res.status(error.status).type('text/plain').send(error.message);
|
|
407
|
-
}
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
//# sourceMappingURL=api-middleware.js.map
|