vike 0.4.218-commit-85af52a → 0.4.218-commit-65f582c
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/dist/cjs/__internal/index.js +2 -3
- package/dist/cjs/node/api/prepareViteApiCall.js +1 -2
- package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +26 -22
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +111 -181
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +2 -2
- package/dist/cjs/node/prerender/runPrerender.js +73 -32
- package/dist/cjs/node/prerender/utils.js +1 -0
- package/dist/cjs/node/runtime/globalContext.js +31 -5
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +11 -33
- package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +9 -1
- package/dist/cjs/node/runtime/renderPage.js +21 -22
- package/dist/cjs/node/shared/assertRuntimeManifest.js +0 -2
- package/dist/cjs/shared/getPageFiles/getPageFiles.js +6 -3
- package/dist/cjs/shared/page-configs/getPageConfigUserFriendly.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +4 -4
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +22 -14
- package/dist/esm/__internal/index.js +2 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.js +1 -4
- package/dist/esm/client/server-routing-runtime/getPageContext.js +1 -4
- package/dist/esm/node/api/prepareViteApiCall.js +1 -2
- package/dist/esm/node/plugin/plugins/baseUrls.js +1 -1
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +2 -4
- package/dist/esm/node/plugin/plugins/commonConfig.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +6 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +25 -21
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +1 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +108 -178
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +2 -2
- package/dist/esm/node/prerender/runPrerender.js +75 -34
- package/dist/esm/node/prerender/utils.d.ts +1 -0
- package/dist/esm/node/prerender/utils.js +1 -0
- package/dist/esm/node/runtime/globalContext.d.ts +17 -3
- package/dist/esm/node/runtime/globalContext.js +32 -6
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +27 -42
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +11 -33
- package/dist/esm/node/runtime/renderPage/resolveRedirects.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/resolveRedirects.js +9 -1
- package/dist/esm/node/runtime/renderPage.js +22 -23
- package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -1
- package/dist/esm/node/shared/assertRuntimeManifest.d.ts +0 -1
- package/dist/esm/node/shared/assertRuntimeManifest.js +1 -3
- package/dist/esm/shared/getPageFiles/getPageFiles.d.ts +2 -0
- package/dist/esm/shared/getPageFiles/getPageFiles.js +6 -3
- package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +9 -5
- package/dist/esm/shared/page-configs/Config.d.ts +13 -1
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.d.ts +7 -4
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.js +2 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +2 -6
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +4 -4
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSetup.js +22 -14
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
|
@@ -108,6 +108,7 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
108
108
|
const { outDirClient } = (0, utils_js_1.getOutDirs)(viteConfig);
|
|
109
109
|
const { root } = viteConfig;
|
|
110
110
|
const prerenderConfig = vikeConfig.vikeConfigGlobal.prerender;
|
|
111
|
+
validatePrerenderConfig(prerenderConfig);
|
|
111
112
|
if (!prerenderConfig) {
|
|
112
113
|
(0, utils_js_1.assert)(standaloneTrigger);
|
|
113
114
|
(0, utils_js_1.assertWarning)(prerenderConfig, `You're executing ${picocolors_1.default.cyan(standaloneTrigger)} but the config ${picocolors_1.default.cyan('prerender')} isn't set to true`, {
|
|
@@ -117,8 +118,8 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
117
118
|
const { partial = false, noExtraDir = false, parallel = true } = prerenderConfig || {};
|
|
118
119
|
const concurrencyLimit = (0, utils_js_1.pLimit)(parallel === false || parallel === 0 ? 1 : parallel === true || parallel === undefined ? (0, os_1.cpus)().length : parallel);
|
|
119
120
|
await (0, globalContext_js_1.initGlobalContext_runPrerender)();
|
|
120
|
-
const
|
|
121
|
-
|
|
121
|
+
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
122
|
+
globalContext.pageFilesAll.forEach(assertExportNames);
|
|
122
123
|
const prerenderContext = {};
|
|
123
124
|
(0, utils_js_1.objectAssign)(prerenderContext, {
|
|
124
125
|
_urlHandler: null,
|
|
@@ -127,10 +128,10 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
127
128
|
pageContextInit: options.pageContextInit ?? null
|
|
128
129
|
});
|
|
129
130
|
const doNotPrerenderList = [];
|
|
130
|
-
await collectDoNoPrerenderList(
|
|
131
|
-
await callOnBeforePrerenderStartHooks(prerenderContext,
|
|
132
|
-
await handlePagesWithStaticRoutes(prerenderContext,
|
|
133
|
-
await callOnPrerenderStartHook(prerenderContext
|
|
131
|
+
await collectDoNoPrerenderList(vikeConfig.pageConfigs, doNotPrerenderList, concurrencyLimit);
|
|
132
|
+
await callOnBeforePrerenderStartHooks(prerenderContext, concurrencyLimit, doNotPrerenderList);
|
|
133
|
+
await handlePagesWithStaticRoutes(prerenderContext, doNotPrerenderList, concurrencyLimit);
|
|
134
|
+
await callOnPrerenderStartHook(prerenderContext);
|
|
134
135
|
const prerenderedPageContexts = {};
|
|
135
136
|
let prerenderedCount = 0;
|
|
136
137
|
const onComplete = async (htmlFile) => {
|
|
@@ -142,14 +143,14 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
142
143
|
};
|
|
143
144
|
await routeAndPrerender(prerenderContext, concurrencyLimit, onComplete);
|
|
144
145
|
warnContradictoryNoPrerenderList(prerenderedPageContexts, doNotPrerenderList);
|
|
145
|
-
await prerender404(prerenderedPageContexts,
|
|
146
|
+
await prerender404(prerenderedPageContexts, prerenderContext, onComplete);
|
|
146
147
|
if (logLevel === 'info') {
|
|
147
148
|
console.log(`${picocolors_1.default.green(`✓`)} ${prerenderedCount} HTML documents pre-rendered.`);
|
|
148
149
|
}
|
|
149
|
-
warnMissingPages(prerenderedPageContexts, doNotPrerenderList,
|
|
150
|
+
warnMissingPages(prerenderedPageContexts, doNotPrerenderList, partial);
|
|
150
151
|
return { viteConfig };
|
|
151
152
|
}
|
|
152
|
-
async function collectDoNoPrerenderList(
|
|
153
|
+
async function collectDoNoPrerenderList(pageConfigs, doNotPrerenderList, concurrencyLimit) {
|
|
153
154
|
// V1 design
|
|
154
155
|
pageConfigs.forEach((pageConfig) => {
|
|
155
156
|
const configName = 'prerender';
|
|
@@ -167,7 +168,8 @@ async function collectDoNoPrerenderList(renderContext, pageConfigs, doNotPrerend
|
|
|
167
168
|
});
|
|
168
169
|
// Old design
|
|
169
170
|
// TODO/v1-release: remove
|
|
170
|
-
|
|
171
|
+
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
172
|
+
await Promise.all(globalContext.pageFilesAll
|
|
171
173
|
.filter((p) => {
|
|
172
174
|
assertExportNames(p);
|
|
173
175
|
if (!p.exportNames?.includes('doNotPrerender'))
|
|
@@ -179,8 +181,8 @@ async function collectDoNoPrerenderList(renderContext, pageConfigs, doNotPrerend
|
|
|
179
181
|
(0, utils_js_1.assert)(p.loadFile);
|
|
180
182
|
await p.loadFile();
|
|
181
183
|
})));
|
|
182
|
-
|
|
183
|
-
const pageFilesServerSide = (0, getPageFiles_js_1.getPageFilesServerSide)(
|
|
184
|
+
globalContext.allPageIds.forEach((pageId) => {
|
|
185
|
+
const pageFilesServerSide = (0, getPageFiles_js_1.getPageFilesServerSide)(globalContext.pageFilesAll, pageId);
|
|
184
186
|
for (const p of pageFilesServerSide) {
|
|
185
187
|
if (!p.exportNames?.includes('doNotPrerender'))
|
|
186
188
|
continue;
|
|
@@ -209,10 +211,11 @@ function assertExportNames(pageFile) {
|
|
|
209
211
|
const { exportNames, fileType } = pageFile;
|
|
210
212
|
(0, utils_js_1.assert)(exportNames || fileType === '.page.route' || fileType === '.css', pageFile.filePath);
|
|
211
213
|
}
|
|
212
|
-
async function callOnBeforePrerenderStartHooks(prerenderContext,
|
|
214
|
+
async function callOnBeforePrerenderStartHooks(prerenderContext, concurrencyLimit, doNotPrerenderList) {
|
|
213
215
|
const onBeforePrerenderStartHooks = [];
|
|
216
|
+
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
214
217
|
// V1 design
|
|
215
|
-
await Promise.all(
|
|
218
|
+
await Promise.all(globalContext.pageConfigs.map((pageConfig) => concurrencyLimit(async () => {
|
|
216
219
|
const hookName = 'onBeforePrerenderStart';
|
|
217
220
|
const pageConfigLoaded = await (0, loadConfigValues_js_1.loadConfigValues)(pageConfig, false);
|
|
218
221
|
const hook = (0, getHook_js_1.getHookFromPageConfig)(pageConfigLoaded, hookName);
|
|
@@ -228,7 +231,7 @@ async function callOnBeforePrerenderStartHooks(prerenderContext, renderContext,
|
|
|
228
231
|
});
|
|
229
232
|
})));
|
|
230
233
|
// 0.4 design
|
|
231
|
-
await Promise.all(
|
|
234
|
+
await Promise.all(globalContext.pageFilesAll
|
|
232
235
|
.filter((p) => {
|
|
233
236
|
assertExportNames(p);
|
|
234
237
|
if (!p.exportNames?.includes('prerender'))
|
|
@@ -269,7 +272,7 @@ async function callOnBeforePrerenderStartHooks(prerenderContext, renderContext,
|
|
|
269
272
|
(0, utils_js_1.assertUsage)(false, `URL ${picocolors_1.default.cyan(url)} provided ${providedTwice}. Make sure to provide the URL only once instead.`);
|
|
270
273
|
}
|
|
271
274
|
}
|
|
272
|
-
const pageContextNew = createPageContext(url,
|
|
275
|
+
const pageContextNew = createPageContext(url, prerenderContext);
|
|
273
276
|
(0, utils_js_1.objectAssign)(pageContextNew, {
|
|
274
277
|
_providedByHook: {
|
|
275
278
|
hookFilePath,
|
|
@@ -286,9 +289,10 @@ async function callOnBeforePrerenderStartHooks(prerenderContext, renderContext,
|
|
|
286
289
|
});
|
|
287
290
|
})));
|
|
288
291
|
}
|
|
289
|
-
async function handlePagesWithStaticRoutes(prerenderContext,
|
|
292
|
+
async function handlePagesWithStaticRoutes(prerenderContext, doNotPrerenderList, concurrencyLimit) {
|
|
290
293
|
// Pre-render pages with a static route
|
|
291
|
-
|
|
294
|
+
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
295
|
+
await Promise.all(globalContext.pageRoutes.map((pageRoute) => concurrencyLimit(async () => {
|
|
292
296
|
const { pageId } = pageRoute;
|
|
293
297
|
if (doNotPrerenderList.find((p) => p.pageId === pageId)) {
|
|
294
298
|
return;
|
|
@@ -313,7 +317,7 @@ async function handlePagesWithStaticRoutes(prerenderContext, renderContext, doNo
|
|
|
313
317
|
return;
|
|
314
318
|
}
|
|
315
319
|
const routeParams = {};
|
|
316
|
-
const pageContext = createPageContext(urlOriginal,
|
|
320
|
+
const pageContext = createPageContext(urlOriginal, prerenderContext);
|
|
317
321
|
(0, utils_js_1.objectAssign)(pageContext, {
|
|
318
322
|
_providedByHook: null,
|
|
319
323
|
routeParams,
|
|
@@ -331,7 +335,7 @@ async function handlePagesWithStaticRoutes(prerenderContext, renderContext, doNo
|
|
|
331
335
|
prerenderContext.pageContexts.push(pageContext);
|
|
332
336
|
})));
|
|
333
337
|
}
|
|
334
|
-
function createPageContext(urlOriginal,
|
|
338
|
+
function createPageContext(urlOriginal, prerenderContext) {
|
|
335
339
|
const pageContext = {
|
|
336
340
|
_urlHandler: null,
|
|
337
341
|
_urlRewrite: null,
|
|
@@ -343,17 +347,18 @@ function createPageContext(urlOriginal, renderContext, prerenderContext) {
|
|
|
343
347
|
};
|
|
344
348
|
(0, utils_js_1.objectAssign)(pageContextInit, prerenderContext.pageContextInit);
|
|
345
349
|
{
|
|
346
|
-
const pageContextInitEnhanced = (0, renderPageAlreadyRouted_js_1.getPageContextInitEnhanced)(pageContextInit
|
|
350
|
+
const pageContextInitEnhanced = (0, renderPageAlreadyRouted_js_1.getPageContextInitEnhanced)(pageContextInit);
|
|
347
351
|
(0, utils_js_1.objectAssign)(pageContext, pageContextInitEnhanced);
|
|
348
352
|
}
|
|
349
353
|
return pageContext;
|
|
350
354
|
}
|
|
351
|
-
async function callOnPrerenderStartHook(prerenderContext
|
|
355
|
+
async function callOnPrerenderStartHook(prerenderContext) {
|
|
356
|
+
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
352
357
|
let onPrerenderStartHook;
|
|
353
358
|
// V1 design
|
|
354
|
-
if (
|
|
359
|
+
if (globalContext.pageConfigs.length > 0) {
|
|
355
360
|
const hookName = 'onPrerenderStart';
|
|
356
|
-
const hook = (0, getHook_js_1.getHookFromPageConfigGlobal)(
|
|
361
|
+
const hook = (0, getHook_js_1.getHookFromPageConfigGlobal)(globalContext.pageConfigGlobal, hookName);
|
|
357
362
|
if (hook) {
|
|
358
363
|
(0, utils_js_1.assert)(hook.hookName === 'onPrerenderStart');
|
|
359
364
|
onPrerenderStartHook = {
|
|
@@ -365,9 +370,9 @@ async function callOnPrerenderStartHook(prerenderContext, renderContext) {
|
|
|
365
370
|
}
|
|
366
371
|
// Old design
|
|
367
372
|
// TODO/v1-release: remove
|
|
368
|
-
if (
|
|
373
|
+
if (globalContext.pageConfigs.length === 0) {
|
|
369
374
|
const hookTimeout = (0, getHook_js_1.getHookTimeoutDefault)('onBeforePrerender');
|
|
370
|
-
const pageFilesWithOnBeforePrerenderHook =
|
|
375
|
+
const pageFilesWithOnBeforePrerenderHook = globalContext.pageFilesAll.filter((p) => {
|
|
371
376
|
assertExportNames(p);
|
|
372
377
|
if (!p.exportNames?.includes('onBeforePrerender'))
|
|
373
378
|
return false;
|
|
@@ -555,27 +560,28 @@ function warnContradictoryNoPrerenderList(prerenderedPageContexts, doNotPrerende
|
|
|
555
560
|
(0, utils_js_1.assertWarning)(false, `The ${providedByHook.hookName}() hook defined by ${providedByHook.hookFilePath} returns the URL ${picocolors_1.default.cyan(urlOriginal)}, while ${setByConfigFile} sets the config ${picocolors_1.default.cyan(setByConfigName)} to ${picocolors_1.default.cyan(String(setByConfigValue))}. This is contradictory: either don't set the config ${picocolors_1.default.cyan(setByConfigName)} to ${picocolors_1.default.cyan(String(setByConfigValue))} or remove the URL ${picocolors_1.default.cyan(urlOriginal)} from the list of URLs to be pre-rendered.`, { onlyOnce: true });
|
|
556
561
|
});
|
|
557
562
|
}
|
|
558
|
-
function warnMissingPages(prerenderedPageContexts, doNotPrerenderList,
|
|
559
|
-
const
|
|
563
|
+
function warnMissingPages(prerenderedPageContexts, doNotPrerenderList, partial) {
|
|
564
|
+
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
565
|
+
const isV1 = globalContext.pageConfigs.length > 0;
|
|
560
566
|
const hookName = isV1 ? 'onBeforePrerenderStart' : 'prerender';
|
|
561
567
|
/* TODO/after-v1-design-release: document setting `prerender: false` as an alternative to using prerender.partial (both in the warnings and the docs)
|
|
562
568
|
const optOutName = isV1 ? 'prerender' : 'doNotPrerender'
|
|
563
569
|
const msgAddendum = `Explicitly opt-out by setting the config ${optOutName} to ${isV1 ? 'false' : 'true'} or use the option prerender.partial`
|
|
564
570
|
*/
|
|
565
|
-
|
|
571
|
+
globalContext.allPageIds
|
|
566
572
|
.filter((pageId) => !prerenderedPageContexts[pageId])
|
|
567
573
|
.filter((pageId) => !doNotPrerenderList.find((p) => p.pageId === pageId))
|
|
568
|
-
.filter((pageId) => !(0, error_page_js_1.isErrorPage)(pageId,
|
|
574
|
+
.filter((pageId) => !(0, error_page_js_1.isErrorPage)(pageId, globalContext.pageConfigs))
|
|
569
575
|
.forEach((pageId) => {
|
|
570
576
|
const pageAt = isV1 ? pageId : `\`${pageId}.page.*\``;
|
|
571
577
|
(0, utils_js_1.assertWarning)(partial, `Cannot pre-render page ${pageAt} because it has a non-static route, while no ${hookName}() hook returned any URL matching the page's route. You need to use a ${hookName}() hook (https://vike.dev/${hookName}) providing a list of URLs for ${pageAt} that should be pre-rendered. If you don't want to pre-render ${pageAt} then use the option prerender.partial (https://vike.dev/prerender#partial) to suppress this warning.`, { onlyOnce: true });
|
|
572
578
|
});
|
|
573
579
|
}
|
|
574
|
-
async function prerender404(prerenderedPageContexts,
|
|
580
|
+
async function prerender404(prerenderedPageContexts, prerenderContext, onComplete) {
|
|
575
581
|
if (!Object.values(prerenderedPageContexts).find(({ urlOriginal }) => urlOriginal === '/404')) {
|
|
576
582
|
let result;
|
|
577
583
|
try {
|
|
578
|
-
result = await (0, renderPageAlreadyRouted_js_1.prerender404Page)(
|
|
584
|
+
result = await (0, renderPageAlreadyRouted_js_1.prerender404Page)(prerenderContext.pageContextInit);
|
|
579
585
|
}
|
|
580
586
|
catch (err) {
|
|
581
587
|
assertIsNotAbort(err, 'the 404 page');
|
|
@@ -755,3 +761,38 @@ function makePageContextComputedUrlNonEnumerable(pageContexts) {
|
|
|
755
761
|
});
|
|
756
762
|
}
|
|
757
763
|
}
|
|
764
|
+
function validatePrerenderConfig(
|
|
765
|
+
// Guaranteed by configDef.type to be either an object or boolean
|
|
766
|
+
prerenderConfig) {
|
|
767
|
+
if (!prerenderConfig || typeof prerenderConfig === 'boolean')
|
|
768
|
+
return;
|
|
769
|
+
(0, utils_js_1.assert)((0, utils_js_1.isObject)(prerenderConfig));
|
|
770
|
+
const wrongValue = (() => {
|
|
771
|
+
{
|
|
772
|
+
const p = 'partial';
|
|
773
|
+
if (!(0, utils_js_1.hasProp)(prerenderConfig, p, 'boolean') && !(0, utils_js_1.hasProp)(prerenderConfig, p, 'undefined'))
|
|
774
|
+
return { prop: p, errMsg: 'should be a boolean' };
|
|
775
|
+
}
|
|
776
|
+
{
|
|
777
|
+
const p = 'noExtraDir';
|
|
778
|
+
if (!(0, utils_js_1.hasProp)(prerenderConfig, p, 'boolean') && !(0, utils_js_1.hasProp)(prerenderConfig, p, 'undefined'))
|
|
779
|
+
return { prop: p, errMsg: 'should be a boolean' };
|
|
780
|
+
}
|
|
781
|
+
{
|
|
782
|
+
const p = 'disableAutoRun';
|
|
783
|
+
if (!(0, utils_js_1.hasProp)(prerenderConfig, p, 'boolean') && !(0, utils_js_1.hasProp)(prerenderConfig, p, 'undefined'))
|
|
784
|
+
return { prop: p, errMsg: 'should be a boolean' };
|
|
785
|
+
}
|
|
786
|
+
{
|
|
787
|
+
const p = 'parallel';
|
|
788
|
+
if (!(0, utils_js_1.hasProp)(prerenderConfig, p, 'boolean') &&
|
|
789
|
+
!(0, utils_js_1.hasProp)(prerenderConfig, p, 'number') &&
|
|
790
|
+
!(0, utils_js_1.hasProp)(prerenderConfig, p, 'undefined'))
|
|
791
|
+
return { prop: p, errMsg: 'should be a boolean or a number' };
|
|
792
|
+
}
|
|
793
|
+
})();
|
|
794
|
+
if (wrongValue) {
|
|
795
|
+
const { prop, errMsg } = wrongValue;
|
|
796
|
+
(0, utils_js_1.assertUsage)(false, `Setting ${picocolors_1.default.cyan(`prerender.${prop}`)} ${errMsg}`);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
@@ -31,4 +31,5 @@ __exportStar(require("../../utils/assertSetup.js"), exports);
|
|
|
31
31
|
__exportStar(require("../../utils/pLimit.js"), exports);
|
|
32
32
|
__exportStar(require("../../utils/isFilePathAbsoluteFilesystem.js"), exports);
|
|
33
33
|
__exportStar(require("../../utils/isArray.js"), exports);
|
|
34
|
+
__exportStar(require("../../utils/isObject.js"), exports);
|
|
34
35
|
__exportStar(require("../../utils/changeEnumerable.js"), exports);
|
|
@@ -27,6 +27,8 @@ const assertPluginManifest_js_1 = require("../shared/assertPluginManifest.js");
|
|
|
27
27
|
const assertRuntimeManifest_js_1 = require("../shared/assertRuntimeManifest.js");
|
|
28
28
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
29
29
|
const resolveBase_js_1 = require("../shared/resolveBase.js");
|
|
30
|
+
const loadPageRoutes_js_1 = require("../../shared/route/loadPageRoutes.js");
|
|
31
|
+
const assertV1Design_js_1 = require("../shared/assertV1Design.js");
|
|
30
32
|
const debug = (0, utils_js_1.createDebugger)('vike:globalContext');
|
|
31
33
|
const globalObject = (0, utils_js_1.getGlobalObject)('globalContext.ts', getInitialGlobalContext());
|
|
32
34
|
initDevEntry();
|
|
@@ -52,6 +54,7 @@ async function getGlobalContextAsync(isProduction) {
|
|
|
52
54
|
}
|
|
53
55
|
function makePublic(globalContext) {
|
|
54
56
|
const globalContextPublic = {
|
|
57
|
+
// TODO/now: add viteConfig and vikeConfig
|
|
55
58
|
assetsManifest: globalContext.assetsManifest
|
|
56
59
|
};
|
|
57
60
|
// Add internals (and prepended _ prefix to their keys)
|
|
@@ -145,6 +148,7 @@ async function initGlobalContext_getGlobalContextAsync(isProduction) {
|
|
|
145
148
|
}
|
|
146
149
|
await initGlobalContext(isProduction);
|
|
147
150
|
}
|
|
151
|
+
// TODO/now: refactor: move this to the top of the file
|
|
148
152
|
async function initGlobalContext(isProduction) {
|
|
149
153
|
if (globalObject.globalContext) {
|
|
150
154
|
(0, utils_js_1.assert)(globalObject.globalContext.isProduction === isProduction);
|
|
@@ -159,6 +163,7 @@ async function initGlobalContext(isProduction) {
|
|
|
159
163
|
(0, utils_js_1.assert)(vikeConfig);
|
|
160
164
|
(0, utils_js_1.assert)(viteDevServer);
|
|
161
165
|
(0, utils_js_1.assert)(!isPrerendering);
|
|
166
|
+
const { globalConfig, userFiles } = await getPageRuntimeInfo(isProduction);
|
|
162
167
|
const pluginManifest = getRuntimeManifest(vikeConfig.vikeConfigGlobal, viteConfig);
|
|
163
168
|
globalObject.globalContext = {
|
|
164
169
|
isProduction: false,
|
|
@@ -166,11 +171,13 @@ async function initGlobalContext(isProduction) {
|
|
|
166
171
|
assetsManifest: null,
|
|
167
172
|
viteDevServer,
|
|
168
173
|
viteConfig,
|
|
169
|
-
vikeConfig
|
|
174
|
+
vikeConfig: {
|
|
175
|
+
global: globalConfig
|
|
176
|
+
},
|
|
177
|
+
...userFiles,
|
|
170
178
|
baseServer: pluginManifest.baseServer,
|
|
171
179
|
baseAssets: pluginManifest.baseAssets,
|
|
172
180
|
includeAssetsImportedByServer: pluginManifest.includeAssetsImportedByServer,
|
|
173
|
-
redirects: pluginManifest.redirects,
|
|
174
181
|
trailingSlash: pluginManifest.trailingSlash,
|
|
175
182
|
disableUrlNormalization: pluginManifest.disableUrlNormalization
|
|
176
183
|
};
|
|
@@ -179,16 +186,20 @@ async function initGlobalContext(isProduction) {
|
|
|
179
186
|
const buildEntry = await getBuildEntry(globalObject.outDirRoot);
|
|
180
187
|
const { assetsManifest, pluginManifest } = buildEntry;
|
|
181
188
|
(0, getPageFiles_js_1.setPageFiles)(buildEntry.pageFiles);
|
|
189
|
+
const { globalConfig, userFiles } = await getPageRuntimeInfo(isProduction);
|
|
182
190
|
assertViteManifest(assetsManifest);
|
|
183
191
|
(0, assertPluginManifest_js_1.assertPluginManifest)(pluginManifest);
|
|
184
192
|
const globalContext = {
|
|
185
193
|
isProduction: true,
|
|
186
194
|
assetsManifest,
|
|
195
|
+
vikeConfig: {
|
|
196
|
+
global: globalConfig
|
|
197
|
+
},
|
|
198
|
+
...userFiles,
|
|
187
199
|
viteDevServer: null,
|
|
188
200
|
baseServer: pluginManifest.baseServer,
|
|
189
201
|
baseAssets: pluginManifest.baseAssets,
|
|
190
202
|
includeAssetsImportedByServer: pluginManifest.includeAssetsImportedByServer,
|
|
191
|
-
redirects: pluginManifest.redirects,
|
|
192
203
|
trailingSlash: pluginManifest.trailingSlash,
|
|
193
204
|
usesClientRouter: pluginManifest.usesClientRouter,
|
|
194
205
|
disableUrlNormalization: pluginManifest.disableUrlNormalization
|
|
@@ -210,14 +221,29 @@ async function initGlobalContext(isProduction) {
|
|
|
210
221
|
}
|
|
211
222
|
}
|
|
212
223
|
}
|
|
224
|
+
async function getPageRuntimeInfo(isProduction) {
|
|
225
|
+
const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal, globalConfig } = await (0, getPageFiles_js_1.getPageFilesAll)(false, isProduction);
|
|
226
|
+
const { pageRoutes, onBeforeRouteHook } = await (0, loadPageRoutes_js_1.loadPageRoutes)(pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds);
|
|
227
|
+
const userFiles = {
|
|
228
|
+
pageFilesAll,
|
|
229
|
+
pageConfigs,
|
|
230
|
+
pageConfigGlobal,
|
|
231
|
+
allPageIds,
|
|
232
|
+
pageRoutes,
|
|
233
|
+
onBeforeRouteHook
|
|
234
|
+
};
|
|
235
|
+
(0, assertV1Design_js_1.assertV1Design)(
|
|
236
|
+
// pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
|
|
237
|
+
pageConfigs.length > 0, pageFilesAll);
|
|
238
|
+
return { userFiles, globalConfig };
|
|
239
|
+
}
|
|
213
240
|
function getRuntimeManifest(vikeConfigGlobal, viteConfig) {
|
|
214
|
-
const { includeAssetsImportedByServer,
|
|
241
|
+
const { includeAssetsImportedByServer, trailingSlash, disableUrlNormalization } = vikeConfigGlobal;
|
|
215
242
|
const { baseServer, baseAssets } = (0, resolveBase_js_1.resolveBaseFromResolvedConfig)(vikeConfigGlobal.baseServer, vikeConfigGlobal.baseAssets, viteConfig);
|
|
216
243
|
const manifest = {
|
|
217
244
|
baseServer,
|
|
218
245
|
baseAssets,
|
|
219
246
|
includeAssetsImportedByServer,
|
|
220
|
-
redirects,
|
|
221
247
|
trailingSlash,
|
|
222
248
|
disableUrlNormalization
|
|
223
249
|
};
|
|
@@ -7,10 +7,8 @@ exports.renderPageAlreadyRouted = renderPageAlreadyRouted;
|
|
|
7
7
|
exports.prerenderPage = prerenderPage;
|
|
8
8
|
exports.prerender404Page = prerender404Page;
|
|
9
9
|
exports.getPageContextInitEnhanced = getPageContextInitEnhanced;
|
|
10
|
-
exports.getRenderContext = getRenderContext;
|
|
11
10
|
const error_page_js_1 = require("../../../shared/error-page.js");
|
|
12
11
|
const renderHtml_js_1 = require("../html/renderHtml.js");
|
|
13
|
-
const getPageFiles_js_1 = require("../../../shared/getPageFiles/getPageFiles.js");
|
|
14
12
|
const utils_js_1 = require("../utils.js");
|
|
15
13
|
const serializePageContextClientSide_js_1 = require("../html/serializePageContextClientSide.js");
|
|
16
14
|
const getPageContextUrlComputed_js_1 = require("../../../shared/getPageContextUrlComputed.js");
|
|
@@ -23,10 +21,8 @@ const loggerRuntime_js_1 = require("./loggerRuntime.js");
|
|
|
23
21
|
const isNewError_js_1 = require("./isNewError.js");
|
|
24
22
|
const preparePageContextForUserConsumptionServerSide_js_1 = require("./preparePageContextForUserConsumptionServerSide.js");
|
|
25
23
|
const executeGuardHook_js_1 = require("../../../shared/route/executeGuardHook.js");
|
|
26
|
-
const loadPageRoutes_js_1 = require("../../../shared/route/loadPageRoutes.js");
|
|
27
24
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
28
25
|
const isServerSideError_js_1 = require("../../../shared/misc/isServerSideError.js");
|
|
29
|
-
const assertV1Design_js_1 = require("../../shared/assertV1Design.js");
|
|
30
26
|
async function renderPageAlreadyRouted(pageContext) {
|
|
31
27
|
// pageContext.pageId can either be the:
|
|
32
28
|
// - ID of the page matching the routing, or the
|
|
@@ -89,8 +85,9 @@ async function prerenderPage(pageContext) {
|
|
|
89
85
|
return { documentHtml, pageContextSerialized, pageContext };
|
|
90
86
|
}
|
|
91
87
|
}
|
|
92
|
-
async function prerender404Page(
|
|
93
|
-
const
|
|
88
|
+
async function prerender404Page(pageContextInit_) {
|
|
89
|
+
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
90
|
+
const errorPageId = (0, error_page_js_1.getErrorPageId)(globalContext.pageFilesAll, globalContext.pageConfigs);
|
|
94
91
|
if (!errorPageId) {
|
|
95
92
|
return null;
|
|
96
93
|
}
|
|
@@ -109,13 +106,13 @@ async function prerender404Page(renderContext, pageContextInit_) {
|
|
|
109
106
|
};
|
|
110
107
|
(0, utils_js_1.objectAssign)(pageContextInit, pageContextInit_);
|
|
111
108
|
{
|
|
112
|
-
const pageContextInitEnhanced = getPageContextInitEnhanced(pageContextInit
|
|
109
|
+
const pageContextInitEnhanced = getPageContextInitEnhanced(pageContextInit);
|
|
113
110
|
(0, utils_js_1.objectAssign)(pageContext, pageContextInitEnhanced);
|
|
114
111
|
}
|
|
115
112
|
(0, utils_js_1.objectAssign)(pageContext, await (0, loadUserFilesServerSide_js_1.loadUserFilesServerSide)(pageContext));
|
|
116
113
|
return prerenderPage(pageContext);
|
|
117
114
|
}
|
|
118
|
-
function getPageContextInitEnhanced(pageContextInit,
|
|
115
|
+
function getPageContextInitEnhanced(pageContextInit, { ssr: { urlRewrite, urlHandler, isClientSideNavigation } = {
|
|
119
116
|
urlRewrite: null,
|
|
120
117
|
urlHandler: null,
|
|
121
118
|
isClientSideNavigation: false
|
|
@@ -131,12 +128,12 @@ function getPageContextInitEnhanced(pageContextInit, renderContext, { ssr: { url
|
|
|
131
128
|
_baseAssets: globalContext.baseAssets,
|
|
132
129
|
_includeAssetsImportedByServer: globalContext.includeAssetsImportedByServer,
|
|
133
130
|
// TODO: use GloablContext instead
|
|
134
|
-
_pageFilesAll:
|
|
135
|
-
_pageConfigs:
|
|
136
|
-
_pageConfigGlobal:
|
|
137
|
-
_allPageIds:
|
|
138
|
-
_pageRoutes:
|
|
139
|
-
_onBeforeRouteHook:
|
|
131
|
+
_pageFilesAll: globalContext.pageFilesAll,
|
|
132
|
+
_pageConfigs: globalContext.pageConfigs,
|
|
133
|
+
_pageConfigGlobal: globalContext.pageConfigGlobal,
|
|
134
|
+
_allPageIds: globalContext.allPageIds,
|
|
135
|
+
_pageRoutes: globalContext.pageRoutes,
|
|
136
|
+
_onBeforeRouteHook: globalContext.onBeforeRouteHook,
|
|
140
137
|
_pageContextInit: pageContextInit,
|
|
141
138
|
_urlRewrite: urlRewrite,
|
|
142
139
|
_urlHandler: urlHandler,
|
|
@@ -164,22 +161,3 @@ function getPageContextInitEnhanced(pageContextInit, renderContext, { ssr: { url
|
|
|
164
161
|
}
|
|
165
162
|
return pageContextInitEnhanced;
|
|
166
163
|
}
|
|
167
|
-
// TODO: remove getRenderContext() in favor of getGlobalObject() + reloadGlobalContext()
|
|
168
|
-
// TODO: impl GlobalNodeContext + GlobalClientContext + GloablContext, and use GlobalContext instead of RenderContext
|
|
169
|
-
async function getRenderContext() {
|
|
170
|
-
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
171
|
-
const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal } = await (0, getPageFiles_js_1.getPageFilesAll)(false, globalContext.isProduction);
|
|
172
|
-
const { pageRoutes, onBeforeRouteHook } = await (0, loadPageRoutes_js_1.loadPageRoutes)(pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds);
|
|
173
|
-
(0, assertV1Design_js_1.assertV1Design)(
|
|
174
|
-
// pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
|
|
175
|
-
pageConfigs.length > 0, pageFilesAll);
|
|
176
|
-
const renderContext = {
|
|
177
|
-
pageFilesAll,
|
|
178
|
-
pageConfigs,
|
|
179
|
-
pageConfigGlobal,
|
|
180
|
-
allPageIds,
|
|
181
|
-
pageRoutes,
|
|
182
|
-
onBeforeRouteHook
|
|
183
|
-
};
|
|
184
|
-
return renderContext;
|
|
185
|
-
}
|
|
@@ -13,7 +13,8 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
13
13
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)(); // Don't bloat the client
|
|
14
14
|
// TODO/next-major-release: update
|
|
15
15
|
const configSrc = '[vite.config.js > vike({ redirects })]';
|
|
16
|
-
function resolveRedirects(
|
|
16
|
+
function resolveRedirects(redirectsAll, urlPathname) {
|
|
17
|
+
const redirects = merge(redirectsAll);
|
|
17
18
|
for (const [urlSource, urlTarget] of Object.entries(redirects)) {
|
|
18
19
|
const urlResolved = resolveRouteStringRedirect(urlSource, urlTarget, urlPathname);
|
|
19
20
|
if (urlResolved)
|
|
@@ -44,3 +45,10 @@ function assertParams(urlSource, urlTarget) {
|
|
|
44
45
|
}
|
|
45
46
|
});
|
|
46
47
|
}
|
|
48
|
+
function merge(objs) {
|
|
49
|
+
const obj = {};
|
|
50
|
+
objs.forEach((e) => {
|
|
51
|
+
Object.assign(obj, e);
|
|
52
|
+
});
|
|
53
|
+
return obj;
|
|
54
|
+
}
|
|
@@ -66,10 +66,8 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
// Prepare context
|
|
69
|
-
let renderContext;
|
|
70
69
|
try {
|
|
71
70
|
await (0, globalContext_js_1.initGlobalContext_renderPage)();
|
|
72
|
-
renderContext = await (0, renderPageAlreadyRouted_js_1.getRenderContext)();
|
|
73
71
|
}
|
|
74
72
|
catch (err) {
|
|
75
73
|
// Errors are expected since assertUsage() is used in both initGlobalContext_renderPage() and getRenderContext().
|
|
@@ -83,7 +81,7 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
|
83
81
|
return handleInvalidConfig(isConfigInvalid_js_1.isConfigInvalid.err);
|
|
84
82
|
}
|
|
85
83
|
else {
|
|
86
|
-
// From now on,
|
|
84
|
+
// From now on, gloablContext contains all the configuration data; getVikeConfig() isn't called anymore for this request
|
|
87
85
|
}
|
|
88
86
|
// Check Base URL
|
|
89
87
|
assertBaseUrl(pageContextInit);
|
|
@@ -99,9 +97,9 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
|
99
97
|
if (pageContextHttpResponse)
|
|
100
98
|
return pageContextHttpResponse;
|
|
101
99
|
}
|
|
102
|
-
return await renderPageAlreadyPrepared(pageContextInit, httpRequestId,
|
|
100
|
+
return await renderPageAlreadyPrepared(pageContextInit, httpRequestId, []);
|
|
103
101
|
}
|
|
104
|
-
async function renderPageAlreadyPrepared(pageContextInit, httpRequestId,
|
|
102
|
+
async function renderPageAlreadyPrepared(pageContextInit, httpRequestId, pageContextsFromRewrite) {
|
|
105
103
|
(0, abort_js_1.assertNoInfiniteAbortLoop)(pageContextsFromRewrite.length,
|
|
106
104
|
// There doesn't seem to be a way to count the number of HTTP redirects (vike don't have access to the HTTP request headers/cookies)
|
|
107
105
|
// https://stackoverflow.com/questions/9683007/detect-infinite-http-redirect-loop-on-server-side
|
|
@@ -113,7 +111,7 @@ async function renderPageAlreadyPrepared(pageContextInit, httpRequestId, renderC
|
|
|
113
111
|
(0, utils_js_1.objectAssign)(pageContextNominalPageInit, pageContextFromAllRewrites);
|
|
114
112
|
}
|
|
115
113
|
{
|
|
116
|
-
const pageContextInitEnhanced = getPageContextInitEnhancedSSR(pageContextInit,
|
|
114
|
+
const pageContextInitEnhanced = getPageContextInitEnhancedSSR(pageContextInit, pageContextNominalPageInit._urlRewrite, httpRequestId);
|
|
117
115
|
(0, utils_js_1.objectAssign)(pageContextNominalPageInit, pageContextInitEnhanced);
|
|
118
116
|
}
|
|
119
117
|
let errNominalPage;
|
|
@@ -145,10 +143,10 @@ async function renderPageAlreadyPrepared(pageContextInit, httpRequestId, renderC
|
|
|
145
143
|
(0, utils_js_1.assert)(pageContextNominalPageSuccess === undefined);
|
|
146
144
|
(0, utils_js_1.assert)(pageContextNominalPageInit);
|
|
147
145
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContextNominalPageInit, 'urlOriginal', 'string'));
|
|
148
|
-
const pageContextErrorPageInit = await getPageContextErrorPageInit(pageContextInit, errNominalPage, pageContextNominalPageInit,
|
|
146
|
+
const pageContextErrorPageInit = await getPageContextErrorPageInit(pageContextInit, errNominalPage, pageContextNominalPageInit, httpRequestId);
|
|
149
147
|
// Handle `throw redirect()` and `throw render()` while rendering nominal page
|
|
150
148
|
if ((0, abort_js_1.isAbortError)(errNominalPage)) {
|
|
151
|
-
const handled = await handleAbortError(errNominalPage, pageContextsFromRewrite, pageContextInit, pageContextNominalPageInit, httpRequestId,
|
|
149
|
+
const handled = await handleAbortError(errNominalPage, pageContextsFromRewrite, pageContextInit, pageContextNominalPageInit, httpRequestId, pageContextErrorPageInit);
|
|
152
150
|
if (handled.pageContextReturn) {
|
|
153
151
|
// - throw redirect()
|
|
154
152
|
// - throw render(url)
|
|
@@ -161,7 +159,8 @@ async function renderPageAlreadyPrepared(pageContextInit, httpRequestId, renderC
|
|
|
161
159
|
Object.assign(pageContextErrorPageInit, handled.pageContextAbort);
|
|
162
160
|
}
|
|
163
161
|
{
|
|
164
|
-
const
|
|
162
|
+
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
163
|
+
const errorPageId = (0, error_page_js_1.getErrorPageId)(globalContext.pageFilesAll, globalContext.pageConfigs);
|
|
165
164
|
if (!errorPageId) {
|
|
166
165
|
(0, utils_js_1.objectAssign)(pageContextErrorPageInit, { pageId: null });
|
|
167
166
|
return (0, handleErrorWithoutErrorPage_js_1.handleErrorWithoutErrorPage)(pageContextErrorPageInit);
|
|
@@ -177,7 +176,7 @@ async function renderPageAlreadyPrepared(pageContextInit, httpRequestId, renderC
|
|
|
177
176
|
catch (errErrorPage) {
|
|
178
177
|
// Handle `throw redirect()` and `throw render()` while rendering error page
|
|
179
178
|
if ((0, abort_js_1.isAbortError)(errErrorPage)) {
|
|
180
|
-
const handled = await handleAbortError(errErrorPage, pageContextsFromRewrite, pageContextInit, pageContextNominalPageInit, httpRequestId,
|
|
179
|
+
const handled = await handleAbortError(errErrorPage, pageContextsFromRewrite, pageContextInit, pageContextNominalPageInit, httpRequestId, pageContextErrorPageInit);
|
|
181
180
|
// throw render(abortStatusCode)
|
|
182
181
|
if (!handled.pageContextReturn) {
|
|
183
182
|
const pageContextAbort = errErrorPage._pageContextAbort;
|
|
@@ -293,8 +292,8 @@ async function renderPageNominal(pageContext) {
|
|
|
293
292
|
(0, utils_js_1.assert)(pageContext === pageContextAfterRender);
|
|
294
293
|
return pageContextAfterRender;
|
|
295
294
|
}
|
|
296
|
-
async function getPageContextErrorPageInit(pageContextInit, errNominalPage, pageContextNominalPagePartial,
|
|
297
|
-
const pageContextInitEnhanced = getPageContextInitEnhancedSSR(pageContextInit,
|
|
295
|
+
async function getPageContextErrorPageInit(pageContextInit, errNominalPage, pageContextNominalPagePartial, httpRequestId) {
|
|
296
|
+
const pageContextInitEnhanced = getPageContextInitEnhancedSSR(pageContextInit, null, httpRequestId);
|
|
298
297
|
(0, utils_js_1.assert)(errNominalPage);
|
|
299
298
|
const pageContext = {};
|
|
300
299
|
(0, utils_js_1.objectAssign)(pageContext, pageContextInitEnhanced);
|
|
@@ -309,9 +308,9 @@ async function getPageContextErrorPageInit(pageContextInit, errNominalPage, page
|
|
|
309
308
|
(0, utils_js_1.assert)(pageContext.errorWhileRendering);
|
|
310
309
|
return pageContext;
|
|
311
310
|
}
|
|
312
|
-
function getPageContextInitEnhancedSSR(pageContextInit,
|
|
311
|
+
function getPageContextInitEnhancedSSR(pageContextInit, urlRewrite, httpRequestId) {
|
|
313
312
|
const { isClientSideNavigation, _urlHandler } = handlePageContextUrl(pageContextInit.urlOriginal);
|
|
314
|
-
const pageContextInitEnhanced = (0, renderPageAlreadyRouted_js_1.getPageContextInitEnhanced)(pageContextInit,
|
|
313
|
+
const pageContextInitEnhanced = (0, renderPageAlreadyRouted_js_1.getPageContextInitEnhanced)(pageContextInit, {
|
|
315
314
|
ssr: {
|
|
316
315
|
urlRewrite,
|
|
317
316
|
urlHandler: _urlHandler,
|
|
@@ -360,12 +359,12 @@ function normalizeUrl(pageContextInit, httpRequestId) {
|
|
|
360
359
|
return pageContextHttpResponse;
|
|
361
360
|
}
|
|
362
361
|
function getPermanentRedirect(pageContextInit, httpRequestId) {
|
|
363
|
-
const
|
|
364
|
-
const urlWithoutBase = (0, utils_js_1.removeBaseServer)(pageContextInit.urlOriginal, baseServer);
|
|
362
|
+
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
363
|
+
const urlWithoutBase = (0, utils_js_1.removeBaseServer)(pageContextInit.urlOriginal, globalContext.baseServer);
|
|
365
364
|
let origin = null;
|
|
366
365
|
let urlTargetExternal = null;
|
|
367
366
|
let urlTarget = (0, utils_js_1.modifyUrlPathname)(urlWithoutBase, (urlPathname) => {
|
|
368
|
-
const urlTarget = (0, resolveRedirects_js_1.resolveRedirects)(redirects, urlPathname);
|
|
367
|
+
const urlTarget = (0, resolveRedirects_js_1.resolveRedirects)(globalContext.vikeConfig.global.config.redirects ?? [], urlPathname);
|
|
369
368
|
if (urlTarget === null)
|
|
370
369
|
return null;
|
|
371
370
|
if (!(0, utils_js_1.isUrl)(urlTarget)) {
|
|
@@ -393,7 +392,7 @@ function getPermanentRedirect(pageContextInit, httpRequestId) {
|
|
|
393
392
|
if (normalize(urlTarget) === normalize(urlWithoutBase))
|
|
394
393
|
return null;
|
|
395
394
|
if (!originChanged)
|
|
396
|
-
urlTarget = (0, utils_js_1.prependBase)(urlTarget, baseServer);
|
|
395
|
+
urlTarget = (0, utils_js_1.prependBase)(urlTarget, globalContext.baseServer);
|
|
397
396
|
(0, utils_js_1.assert)(urlTarget !== pageContextInit.urlOriginal);
|
|
398
397
|
}
|
|
399
398
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`Permanent redirection defined by config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
|
|
@@ -407,13 +406,14 @@ function normalize(url) {
|
|
|
407
406
|
}
|
|
408
407
|
async function handleAbortError(errAbort, pageContextsFromRewrite, pageContextInit,
|
|
409
408
|
// handleAbortError() creates a new pageContext object and we don't merge pageContextNominalPageInit to it: we only use some pageContextNominalPageInit information.
|
|
410
|
-
pageContextNominalPageInit, httpRequestId,
|
|
409
|
+
pageContextNominalPageInit, httpRequestId, pageContextErrorPageInit) {
|
|
411
410
|
(0, abort_js_1.logAbortErrorHandled)(errAbort, (0, globalContext_js_1.getGlobalContext)().isProduction, pageContextNominalPageInit);
|
|
412
411
|
const pageContextAbort = errAbort._pageContextAbort;
|
|
413
412
|
let pageContextSerialized;
|
|
414
413
|
if (pageContextNominalPageInit.isClientSideNavigation) {
|
|
415
414
|
if (pageContextAbort.abortStatusCode) {
|
|
416
|
-
const
|
|
415
|
+
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
416
|
+
const errorPageId = (0, error_page_js_1.getErrorPageId)(globalContext.pageFilesAll, globalContext.pageConfigs);
|
|
417
417
|
const abortCall = pageContextAbort._abortCall;
|
|
418
418
|
(0, utils_js_1.assert)(abortCall);
|
|
419
419
|
(0, utils_js_1.assertUsage)(errorPageId, `You called ${picocolors_1.default.cyan(abortCall)} but you didn't define an error page, make sure to define one https://vike.dev/error-page`);
|
|
@@ -421,7 +421,6 @@ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageIn
|
|
|
421
421
|
(0, utils_js_1.objectAssign)(pageContext, { pageId: errorPageId });
|
|
422
422
|
(0, utils_js_1.objectAssign)(pageContext, pageContextAbort);
|
|
423
423
|
(0, utils_js_1.objectAssign)(pageContext, pageContextErrorPageInit);
|
|
424
|
-
(0, utils_js_1.objectAssign)(pageContext, renderContext);
|
|
425
424
|
(0, utils_js_1.objectAssign)(pageContext, await (0, loadUserFilesServerSide_js_1.loadUserFilesServerSide)(pageContext));
|
|
426
425
|
// We include pageContextInit: we don't only serialize pageContextAbort because the error page may need to access pageContextInit
|
|
427
426
|
pageContextSerialized = (0, serializePageContextClientSide_js_1.serializePageContextClientSide)(pageContext);
|
|
@@ -434,7 +433,7 @@ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageIn
|
|
|
434
433
|
return { pageContextReturn };
|
|
435
434
|
}
|
|
436
435
|
if (pageContextAbort._urlRewrite) {
|
|
437
|
-
const pageContextReturn = await renderPageAlreadyPrepared(pageContextInit, httpRequestId,
|
|
436
|
+
const pageContextReturn = await renderPageAlreadyPrepared(pageContextInit, httpRequestId, [
|
|
438
437
|
...pageContextsFromRewrite,
|
|
439
438
|
pageContextAbort
|
|
440
439
|
]);
|
|
@@ -10,8 +10,6 @@ function assertRuntimeManifest(obj) {
|
|
|
10
10
|
(0, utils_js_1.assert)((0, utils_js_1.isBaseServer)(obj.baseServer));
|
|
11
11
|
(0, utils_js_1.assert)((0, utils_js_1.isBaseAssets)(obj.baseAssets));
|
|
12
12
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(obj, 'includeAssetsImportedByServer', 'boolean'));
|
|
13
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(obj, 'redirects', 'object'));
|
|
14
|
-
(0, utils_js_1.castType)(obj);
|
|
15
13
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(obj, 'trailingSlash', 'boolean'));
|
|
16
14
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(obj, 'disableUrlNormalization', 'boolean'));
|
|
17
15
|
(0, utils_js_1.checkType)(obj);
|