vike 0.4.147 → 0.4.148-commit-7596dcd
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/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +17 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +116 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +33 -45
- package/dist/cjs/node/prerender/runPrerender.js +85 -84
- package/dist/cjs/node/runtime/html/injectAssets/injectAssets__public.js +1 -1
- package/dist/cjs/node/runtime/html/renderHtml.js +1 -1
- package/dist/cjs/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.js +12 -12
- package/dist/cjs/node/runtime/renderPage/createHttpResponseObject.js +3 -3
- package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderHook.js +1 -1
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +3 -3
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +1 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +21 -18
- package/dist/cjs/node/runtime/renderPage.js +73 -49
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +3 -3
- package/dist/cjs/shared/hooks/executeHook.js +18 -29
- package/dist/cjs/shared/hooks/getHook.js +104 -3
- package/dist/cjs/shared/page-configs/helpers/getConfigDefinedAtString.js +1 -1
- package/dist/cjs/shared/route/executeGuardHook.js +3 -2
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +4 -4
- package/dist/cjs/shared/route/loadPageRoutes.js +10 -15
- package/dist/cjs/shared/route/resolveRedirects.js +8 -5
- package/dist/cjs/utils/parseUrl-extras.js +6 -1
- package/dist/cjs/utils/parseUrl.js +24 -16
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +20 -10
- package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +2 -2
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +18 -12
- package/dist/esm/client/shared/executeOnRenderClientHook.js +1 -1
- package/dist/esm/client/shared/getPageContextSerializedInHtml.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +17 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +110 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +34 -46
- package/dist/esm/node/prerender/runPrerender.js +87 -86
- package/dist/esm/node/runtime/html/injectAssets/injectAssets__public.js +1 -1
- package/dist/esm/node/runtime/html/renderHtml.js +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.js +13 -13
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject.js +3 -3
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderHook.js +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +3 -3
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +1 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +7 -7
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +22 -19
- package/dist/esm/node/runtime/renderPage.js +74 -50
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +1 -1
- package/dist/esm/shared/hooks/executeHook.d.ts +2 -2
- package/dist/esm/shared/hooks/executeHook.js +18 -29
- package/dist/esm/shared/hooks/getHook.d.ts +17 -7
- package/dist/esm/shared/hooks/getHook.js +103 -3
- package/dist/esm/shared/page-configs/Config.d.ts +21 -13
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.d.ts +1 -1
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.js +1 -1
- package/dist/esm/shared/route/executeGuardHook.js +4 -3
- package/dist/esm/shared/route/executeOnBeforeRouteHook.d.ts +1 -8
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +6 -6
- package/dist/esm/shared/route/index.d.ts +2 -2
- package/dist/esm/shared/route/loadPageRoutes.d.ts +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +11 -16
- package/dist/esm/shared/route/resolveRedirects.js +8 -5
- package/dist/esm/utils/parseUrl-extras.d.ts +2 -0
- package/dist/esm/utils/parseUrl-extras.js +5 -0
- package/dist/esm/utils/parseUrl.js +24 -16
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +3 -3
- /package/dist/cjs/shared/page-configs/serialize/{assertPageConfigs.js → assertPageConfigsSerialized.js} +0 -0
- /package/dist/esm/shared/page-configs/serialize/{assertPageConfigs.d.ts → assertPageConfigsSerialized.d.ts} +0 -0
- /package/dist/esm/shared/page-configs/serialize/{assertPageConfigs.js → assertPageConfigsSerialized.js} +0 -0
package/dist/cjs/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.js
CHANGED
|
@@ -9,21 +9,21 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
9
9
|
const globalObject = (0, utils_js_1.getGlobalObject)('assertNoInfiniteHttpRedirect.ts', {
|
|
10
10
|
redirectGraph: {}
|
|
11
11
|
});
|
|
12
|
-
function assertNoInfiniteHttpRedirect(
|
|
13
|
-
if (
|
|
14
|
-
// We assume that
|
|
15
|
-
// - There isn't a reliable way to check whether the redirect points to an external origin or the same origin
|
|
12
|
+
function assertNoInfiniteHttpRedirect(urlRedirectTarget, urlLogical) {
|
|
13
|
+
if ((0, utils_js_1.isUriWithProtocol)(urlRedirectTarget)) {
|
|
14
|
+
// We assume that urlRedirectTarget points to an origin that is external (not the same origin), and we can therefore assume that the app doesn't define an infinite loop (in itself).
|
|
15
|
+
// - There isn't a reliable way to check whether the redirect points to an external origin or the same origin. For same origins, we assume/hope the user to pass the URL without origin.
|
|
16
16
|
// ```js
|
|
17
|
-
// //
|
|
17
|
+
// // For same-origin, the user usually/hopefully passes a URL without origin
|
|
18
18
|
// renderPage({ urlOriginal: '/some/pathname' })
|
|
19
19
|
// ```
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
(0, utils_js_1.assert)(
|
|
23
|
-
(0, utils_js_1.assert)(
|
|
22
|
+
(0, utils_js_1.assert)(urlRedirectTarget.startsWith('/'));
|
|
23
|
+
(0, utils_js_1.assert)(urlLogical.startsWith('/'));
|
|
24
24
|
const graph = copy(globalObject.redirectGraph);
|
|
25
|
-
graph[
|
|
26
|
-
graph[
|
|
25
|
+
graph[urlRedirectTarget] ?? (graph[urlRedirectTarget] = new Set());
|
|
26
|
+
graph[urlRedirectTarget].add(urlLogical);
|
|
27
27
|
validate(graph);
|
|
28
28
|
globalObject.redirectGraph = graph;
|
|
29
29
|
}
|
|
@@ -32,6 +32,9 @@ function copy(G) {
|
|
|
32
32
|
return Object.fromEntries(Object.entries(G).map(([key, val]) => [key, new Set(val)]));
|
|
33
33
|
}
|
|
34
34
|
// Adapted from: https://stackoverflow.com/questions/60904464/detect-cycle-in-directed-graph/60907076#60907076
|
|
35
|
+
function validate(G) {
|
|
36
|
+
Object.keys(G).forEach((n) => check(G, n, []));
|
|
37
|
+
}
|
|
35
38
|
function check(G, n, path) {
|
|
36
39
|
if (path.includes(n)) {
|
|
37
40
|
const cycle = path.slice(path.indexOf(n)).concat(n);
|
|
@@ -39,6 +42,3 @@ function check(G, n, path) {
|
|
|
39
42
|
}
|
|
40
43
|
G[n]?.forEach((node) => check(G, node, [...path, n]));
|
|
41
44
|
}
|
|
42
|
-
function validate(G) {
|
|
43
|
-
Object.keys(G).forEach((n) => check(G, n, []));
|
|
44
|
-
}
|
|
@@ -35,9 +35,9 @@ async function createHttpResponsePageContextJson(pageContextSerialized) {
|
|
|
35
35
|
}
|
|
36
36
|
exports.createHttpResponsePageContextJson = createHttpResponsePageContextJson;
|
|
37
37
|
function createHttpResponseObjectRedirect({ url, statusCode },
|
|
38
|
-
// The URL
|
|
39
|
-
|
|
40
|
-
(0, assertNoInfiniteHttpRedirect_js_1.assertNoInfiniteHttpRedirect)(url,
|
|
38
|
+
// The URL we assume the redirect to be logically based on
|
|
39
|
+
urlLogical) {
|
|
40
|
+
(0, assertNoInfiniteHttpRedirect_js_1.assertNoInfiniteHttpRedirect)(url, urlLogical);
|
|
41
41
|
(0, utils_js_1.assert)(url);
|
|
42
42
|
(0, utils_js_1.assert)(statusCode);
|
|
43
43
|
(0, utils_js_1.assert)(300 <= statusCode && statusCode <= 399);
|
|
@@ -15,7 +15,7 @@ async function executeOnBeforeRenderHooks(pageContext) {
|
|
|
15
15
|
}
|
|
16
16
|
const onBeforeRender = hook.hookFn;
|
|
17
17
|
(0, preparePageContextForUserConsumptionServerSide_js_1.preparePageContextForUserConsumptionServerSide)(pageContext);
|
|
18
|
-
const hookResult = await (0, utils_js_1.executeHook)(() => onBeforeRender(pageContext),
|
|
18
|
+
const hookResult = await (0, utils_js_1.executeHook)(() => onBeforeRender(pageContext), hook);
|
|
19
19
|
(0, assertOnBeforeRenderHookReturn_js_1.assertOnBeforeRenderHookReturn)(hookResult, hook.hookFilePath);
|
|
20
20
|
const pageContextFromHook = hookResult?.pageContext;
|
|
21
21
|
Object.assign(pageContext, pageContextFromHook);
|
|
@@ -17,7 +17,7 @@ async function executeOnRenderHtmlHook(pageContext) {
|
|
|
17
17
|
const { renderHook, hookFn } = getRenderHook(pageContext);
|
|
18
18
|
(0, utils_js_1.objectAssign)(pageContext, { _renderHook: renderHook });
|
|
19
19
|
(0, preparePageContextForUserConsumptionServerSide_js_1.preparePageContextForUserConsumptionServerSide)(pageContext);
|
|
20
|
-
const hookReturnValue = await (0, utils_js_1.executeHook)(() => hookFn(pageContext), renderHook
|
|
20
|
+
const hookReturnValue = await (0, utils_js_1.executeHook)(() => hookFn(pageContext), renderHook);
|
|
21
21
|
const { documentHtml, pageContextProvidedByRenderHook, pageContextPromise, injectFilter } = processHookReturnValue(hookReturnValue, renderHook);
|
|
22
22
|
Object.assign(pageContext, pageContextProvidedByRenderHook);
|
|
23
23
|
(0, utils_js_1.objectAssign)(pageContext, { _pageContextPromise: pageContextPromise });
|
|
@@ -56,10 +56,10 @@ function getRenderHook(pageContext) {
|
|
|
56
56
|
}
|
|
57
57
|
if (hook) {
|
|
58
58
|
(0, utils_js_1.assert)(hookName);
|
|
59
|
-
const { hookFilePath, hookFn } = hook;
|
|
59
|
+
const { hookFilePath, hookFn, hookTimeout } = hook;
|
|
60
60
|
hookFound = {
|
|
61
61
|
hookFn,
|
|
62
|
-
renderHook: { hookFilePath, hookName }
|
|
62
|
+
renderHook: { hookFn, hookFilePath, hookName, hookTimeout }
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -11,7 +11,7 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
11
11
|
const streamDocs = 'See https://vike.dev/stream for more information.';
|
|
12
12
|
function getHttpResponseBody(htmlRender, renderHook) {
|
|
13
13
|
if (typeof htmlRender !== 'string') {
|
|
14
|
-
(0, utils_js_1.assertUsage)(false, getErrMsg(htmlRender, renderHook, 'body', `Use ${picocolors_1.default.cyan('pageContext.httpResponse.pipe()')}
|
|
14
|
+
(0, utils_js_1.assertUsage)(false, getErrMsg(htmlRender, renderHook, 'body', `Use ${picocolors_1.default.cyan('pageContext.httpResponse.pipe()')} instead`));
|
|
15
15
|
}
|
|
16
16
|
const body = htmlRender;
|
|
17
17
|
return body;
|
|
@@ -155,7 +155,7 @@ async function getRenderContext() {
|
|
|
155
155
|
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
156
156
|
const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal } = await (0, getPageFiles_js_1.getPageFilesAll)(false, globalContext.isProduction);
|
|
157
157
|
const { pageRoutes, onBeforeRouteHook } = await (0, loadPageRoutes_js_1.loadPageRoutes)(pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds);
|
|
158
|
-
|
|
158
|
+
assertV1Design(pageFilesAll, pageConfigs);
|
|
159
159
|
const renderContext = {
|
|
160
160
|
pageFilesAll: pageFilesAll,
|
|
161
161
|
pageConfigs,
|
|
@@ -167,21 +167,24 @@ async function getRenderContext() {
|
|
|
167
167
|
return renderContext;
|
|
168
168
|
}
|
|
169
169
|
exports.getRenderContext = getRenderContext;
|
|
170
|
-
function
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
170
|
+
function assertV1Design(pageFilesAll, pageConfigs) {
|
|
171
|
+
const isV1Design = pageConfigs.length !== 0;
|
|
172
|
+
const isDesignOld = pageFilesAll.length !== 0;
|
|
173
|
+
if (isV1Design && isDesignOld) {
|
|
174
|
+
const indent = '- ';
|
|
175
|
+
const v1Files = (0, utils_js_1.unique)(pageConfigs
|
|
176
|
+
.map((p) => Object.values(p.configValues)
|
|
177
|
+
.map(helpers_js_1.getConfigValueFilePathToShowToUser)
|
|
178
|
+
.filter(utils_js_1.isNotNullish)
|
|
179
|
+
.map((filePathToShowToUser) => indent + filePathToShowToUser))
|
|
180
|
+
.flat(2));
|
|
181
|
+
(0, utils_js_1.assertUsage)(false, [
|
|
182
|
+
'Mixing the new V1 design with the old V0.4 design is forbidden.',
|
|
183
|
+
'V1 files:',
|
|
184
|
+
...v1Files,
|
|
185
|
+
'V0.4 files:',
|
|
186
|
+
...pageFilesAll.map((p) => indent + p.filePath)
|
|
187
|
+
].join('\n'));
|
|
188
|
+
}
|
|
189
|
+
(0, utils_js_1.assertWarning)(!isDesignOld, 'You are using the old deprecated design, update to the new V1 design, see https://vike.dev/migration/v1-design', { onlyOnce: true });
|
|
187
190
|
}
|
|
@@ -39,17 +39,17 @@ async function renderPage(pageContextInit) {
|
|
|
39
39
|
(0, assertArguments_js_1.assertArguments)(...arguments);
|
|
40
40
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContextInit, 'urlOriginal', 'string'));
|
|
41
41
|
(0, utils_js_1.assertEnv)();
|
|
42
|
-
if (
|
|
43
|
-
const
|
|
44
|
-
(0, utils_js_1.checkType)(
|
|
45
|
-
return
|
|
42
|
+
if (isIgnoredUrl(pageContextInit.urlOriginal)) {
|
|
43
|
+
const pageContextHttpResponseNull = getPageContextHttpResponseNull(pageContextInit);
|
|
44
|
+
(0, utils_js_1.checkType)(pageContextHttpResponseNull);
|
|
45
|
+
return pageContextHttpResponseNull;
|
|
46
46
|
}
|
|
47
47
|
const httpRequestId = getRequestId();
|
|
48
|
-
const
|
|
49
|
-
logHttpRequest(
|
|
48
|
+
const { urlOriginal } = pageContextInit;
|
|
49
|
+
logHttpRequest(urlOriginal, httpRequestId);
|
|
50
50
|
globalObject.pendingRequestsCount++;
|
|
51
51
|
const { pageContextReturn, onRequestDone } = await renderPage_wrapper(httpRequestId, () => renderPageAndPrepare(pageContextInit, httpRequestId));
|
|
52
|
-
logHttpResponse(
|
|
52
|
+
logHttpResponse(urlOriginal, httpRequestId, pageContextReturn);
|
|
53
53
|
globalObject.pendingRequestsCount--;
|
|
54
54
|
onRequestDone();
|
|
55
55
|
(0, utils_js_1.checkType)(pageContextReturn);
|
|
@@ -60,8 +60,8 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
|
60
60
|
// Invalid config
|
|
61
61
|
const handleInvalidConfig = () => {
|
|
62
62
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(picocolors_1.default.bold(picocolors_1.default.red("Couldn't load configuration: see error above.")), httpRequestId, 'error');
|
|
63
|
-
const
|
|
64
|
-
return
|
|
63
|
+
const pageContextHttpResponseNull = getPageContextHttpResponseNull(pageContextInit);
|
|
64
|
+
return pageContextHttpResponseNull;
|
|
65
65
|
};
|
|
66
66
|
if (isConfigInvalid_js_1.isConfigInvalid) {
|
|
67
67
|
return handleInvalidConfig();
|
|
@@ -77,8 +77,8 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
|
77
77
|
// initGlobalContext() and getRenderContext() don't call any user hooks => err isn't thrown from user code
|
|
78
78
|
(0, utils_js_1.assert)(!(0, abort_js_1.isAbortError)(err));
|
|
79
79
|
(0, loggerRuntime_js_1.logRuntimeError)(err, httpRequestId);
|
|
80
|
-
const
|
|
81
|
-
return
|
|
80
|
+
const pageContextHttpResponseNull = getPageContextHttpResponseNullWithError(err, pageContextInit);
|
|
81
|
+
return pageContextHttpResponseNull;
|
|
82
82
|
}
|
|
83
83
|
if (isConfigInvalid_js_1.isConfigInvalid) {
|
|
84
84
|
return handleInvalidConfig();
|
|
@@ -86,15 +86,23 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
|
86
86
|
else {
|
|
87
87
|
// From now on, renderContext.pageConfigs contains all the configuration data; getVikeConfig() isn't called anymore for this request
|
|
88
88
|
}
|
|
89
|
+
// Check Base URL
|
|
90
|
+
{
|
|
91
|
+
const pageContextHttpResponse = checkBaseUrl(pageContextInit, httpRequestId);
|
|
92
|
+
if (pageContextHttpResponse)
|
|
93
|
+
return pageContextHttpResponse;
|
|
94
|
+
}
|
|
95
|
+
// Normalize URL
|
|
89
96
|
{
|
|
90
|
-
const
|
|
91
|
-
if (
|
|
92
|
-
return
|
|
97
|
+
const pageContextHttpResponse = normalizeUrl(pageContextInit, httpRequestId);
|
|
98
|
+
if (pageContextHttpResponse)
|
|
99
|
+
return pageContextHttpResponse;
|
|
93
100
|
}
|
|
101
|
+
// Permanent redirects (HTTP status code `301`)
|
|
94
102
|
{
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
return
|
|
103
|
+
const pageContextHttpResponse = getPermanentRedirect(pageContextInit, httpRequestId);
|
|
104
|
+
if (pageContextHttpResponse)
|
|
105
|
+
return pageContextHttpResponse;
|
|
98
106
|
}
|
|
99
107
|
return await renderPageAlreadyPrepared(pageContextInit, httpRequestId, renderContext, []);
|
|
100
108
|
}
|
|
@@ -177,8 +185,8 @@ async function renderPageAlreadyPrepared(pageContextInit, httpRequestId, renderC
|
|
|
177
185
|
if (!handled.pageContextReturn) {
|
|
178
186
|
const pageContextAbort = errErrorPage._pageContextAbort;
|
|
179
187
|
(0, utils_js_1.assertWarning)(false, `Failed to render error page because ${picocolors_1.default.cyan(pageContextAbort._abortCall)} was called: make sure ${picocolors_1.default.cyan(pageContextAbort._abortCaller)} doesn't occur while the error page is being rendered.`, { onlyOnce: false });
|
|
180
|
-
const
|
|
181
|
-
return
|
|
188
|
+
const pageContextHttpResponseNull = getPageContextHttpResponseNullWithError(errNominalPage, pageContextInit);
|
|
189
|
+
return pageContextHttpResponseNull;
|
|
182
190
|
}
|
|
183
191
|
// `throw redirect()` / `throw render(url)`
|
|
184
192
|
return handled.pageContextReturn;
|
|
@@ -186,18 +194,28 @@ async function renderPageAlreadyPrepared(pageContextInit, httpRequestId, renderC
|
|
|
186
194
|
if ((0, isNewError_js_1.isNewError)(errErrorPage, errNominalPage)) {
|
|
187
195
|
(0, loggerRuntime_js_1.logRuntimeError)(errErrorPage, httpRequestId);
|
|
188
196
|
}
|
|
189
|
-
const
|
|
190
|
-
return
|
|
197
|
+
const pageContextHttpResponseNull = getPageContextHttpResponseNullWithError(errNominalPage, pageContextInit);
|
|
198
|
+
return pageContextHttpResponseNull;
|
|
191
199
|
}
|
|
192
200
|
return pageContextErrorPage;
|
|
193
201
|
}
|
|
194
202
|
}
|
|
195
|
-
function logHttpRequest(
|
|
203
|
+
function logHttpRequest(urlOriginal, httpRequestId) {
|
|
196
204
|
const clearErrors = globalObject.pendingRequestsCount === 0;
|
|
197
|
-
(0, loggerRuntime_js_1.logRuntimeInfo)?.(
|
|
205
|
+
(0, loggerRuntime_js_1.logRuntimeInfo)?.(getRequestInfoMessage(urlOriginal), httpRequestId, 'info', clearErrors);
|
|
198
206
|
}
|
|
199
|
-
function
|
|
207
|
+
function getRequestInfoMessage(urlOriginal) {
|
|
208
|
+
return `HTTP request: ${picocolors_1.default.bold(urlOriginal)}`;
|
|
209
|
+
}
|
|
210
|
+
function logHttpResponse(urlOriginal, httpRequestId, pageContextReturn) {
|
|
200
211
|
const statusCode = pageContextReturn.httpResponse?.statusCode ?? null;
|
|
212
|
+
{
|
|
213
|
+
// If URL doesn't include Base URL
|
|
214
|
+
const { errorWhileRendering } = pageContextReturn;
|
|
215
|
+
const isSkipped = statusCode === null && (errorWhileRendering === null || errorWhileRendering === undefined);
|
|
216
|
+
if (isSkipped)
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
201
219
|
const isSuccess = statusCode !== null && statusCode >= 200 && statusCode <= 399;
|
|
202
220
|
const isNominal = isSuccess || statusCode === 404;
|
|
203
221
|
const color = (s) => picocolors_1.default.bold(isSuccess ? picocolors_1.default.green(String(s)) : picocolors_1.default.red(String(s)));
|
|
@@ -211,39 +229,30 @@ function logHttpResponse(urlToShowToUser, httpRequestId, pageContextReturn) {
|
|
|
211
229
|
.find((header) => header[0] === 'Location');
|
|
212
230
|
(0, utils_js_1.assert)(headerRedirect);
|
|
213
231
|
const urlRedirect = headerRedirect[1];
|
|
214
|
-
|
|
232
|
+
urlOriginal = urlRedirect;
|
|
215
233
|
}
|
|
216
|
-
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`HTTP ${type} ${picocolors_1.default.bold(
|
|
234
|
+
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`HTTP ${type} ${picocolors_1.default.bold(urlOriginal)} ${color(statusCode ?? 'ERR')}`, httpRequestId, isNominal ? 'info' : 'error');
|
|
217
235
|
}
|
|
218
236
|
function getPageContextHttpResponseNullWithError(err, pageContextInit) {
|
|
219
|
-
const
|
|
220
|
-
(0, utils_js_1.objectAssign)(
|
|
221
|
-
(0, utils_js_1.objectAssign)(
|
|
237
|
+
const pageContextHttpResponseNull = {};
|
|
238
|
+
(0, utils_js_1.objectAssign)(pageContextHttpResponseNull, pageContextInit);
|
|
239
|
+
(0, utils_js_1.objectAssign)(pageContextHttpResponseNull, {
|
|
222
240
|
httpResponse: null,
|
|
223
241
|
errorWhileRendering: err
|
|
224
242
|
});
|
|
225
|
-
return
|
|
243
|
+
return pageContextHttpResponseNull;
|
|
226
244
|
}
|
|
227
245
|
function getPageContextHttpResponseNull(pageContextInit) {
|
|
228
|
-
const
|
|
229
|
-
(0, utils_js_1.objectAssign)(
|
|
230
|
-
(0, utils_js_1.objectAssign)(
|
|
246
|
+
const pageContextHttpResponseNull = {};
|
|
247
|
+
(0, utils_js_1.objectAssign)(pageContextHttpResponseNull, pageContextInit);
|
|
248
|
+
(0, utils_js_1.objectAssign)(pageContextHttpResponseNull, {
|
|
231
249
|
httpResponse: null,
|
|
232
250
|
errorWhileRendering: null
|
|
233
251
|
});
|
|
234
|
-
return
|
|
252
|
+
return pageContextHttpResponseNull;
|
|
235
253
|
}
|
|
236
254
|
async function renderPageNominal(pageContext) {
|
|
237
255
|
(0, utils_js_1.objectAssign)(pageContext, { errorWhileRendering: null });
|
|
238
|
-
// Check Base URL
|
|
239
|
-
{
|
|
240
|
-
const { urlWithoutPageContextRequestSuffix } = (0, handlePageContextRequestUrl_js_1.handlePageContextRequestUrl)(pageContext.urlOriginal);
|
|
241
|
-
const hasBaseServer = (0, utils_js_1.parseUrl)(urlWithoutPageContextRequestSuffix, pageContext._baseServer).hasBaseServer || !!pageContext._urlRewrite;
|
|
242
|
-
if (!hasBaseServer) {
|
|
243
|
-
(0, utils_js_1.objectAssign)(pageContext, { httpResponse: null });
|
|
244
|
-
return pageContext;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
256
|
// Route
|
|
248
257
|
{
|
|
249
258
|
const pageContextFromRoute = await (0, index_js_1.route)(pageContext);
|
|
@@ -309,7 +318,7 @@ function getRequestId() {
|
|
|
309
318
|
(0, utils_js_1.assert)(httpRequestId >= 1);
|
|
310
319
|
return httpRequestId;
|
|
311
320
|
}
|
|
312
|
-
function
|
|
321
|
+
function isIgnoredUrl(urlOriginal) {
|
|
313
322
|
const isViteClientRequest = urlOriginal.endsWith('/@vite/client') || urlOriginal.startsWith('/@fs/');
|
|
314
323
|
(0, utils_js_1.assertWarning)(!isViteClientRequest, `The vike middleware renderPage() was called with the URL ${urlOriginal} which is unexpected because the HTTP request should have already been handled by Vite's development middleware. Make sure to 1. install Vite's development middleware and 2. add Vite's middleware *before* Vike's middleware, see https://vike.dev/renderPage`, { onlyOnce: true });
|
|
315
324
|
return (urlOriginal.endsWith('/__vite_ping') ||
|
|
@@ -333,10 +342,8 @@ function normalizeUrl(pageContextInit, httpRequestId) {
|
|
|
333
342
|
function getPermanentRedirect(pageContextInit, httpRequestId) {
|
|
334
343
|
const { redirects, baseServer } = (0, globalContext_js_1.getGlobalContext)();
|
|
335
344
|
const urlWithoutBase = (0, utils_js_1.removeBaseServer)(pageContextInit.urlOriginal, baseServer);
|
|
336
|
-
let urlOriginalPathnameWithouBase;
|
|
337
345
|
let origin = null;
|
|
338
346
|
let urlTarget = (0, utils_js_1.modifyUrlPathname)(urlWithoutBase, (urlPathname) => {
|
|
339
|
-
urlOriginalPathnameWithouBase = urlPathname;
|
|
340
347
|
const urlTargetWithOrigin = (0, resolveRedirects_js_1.resolveRedirects)(redirects, urlPathname);
|
|
341
348
|
if (urlTargetWithOrigin === null)
|
|
342
349
|
return null;
|
|
@@ -346,13 +353,12 @@ function getPermanentRedirect(pageContextInit, httpRequestId) {
|
|
|
346
353
|
});
|
|
347
354
|
if (origin)
|
|
348
355
|
urlTarget = (0, utils_js_1.addUrlOrigin)(urlTarget, origin);
|
|
349
|
-
(0, utils_js_1.assert)(urlOriginalPathnameWithouBase);
|
|
350
356
|
if (urlTarget === urlWithoutBase)
|
|
351
357
|
return null;
|
|
352
358
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`Permanent redirect defined by your config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
|
|
353
359
|
urlTarget = (0, utils_js_1.prependBase)(urlTarget, baseServer);
|
|
354
360
|
(0, utils_js_1.assert)(urlTarget !== pageContextInit.urlOriginal);
|
|
355
|
-
const httpResponse = (0, createHttpResponseObject_js_1.createHttpResponseObjectRedirect)({ url: urlTarget, statusCode: 301 },
|
|
361
|
+
const httpResponse = (0, createHttpResponseObject_js_1.createHttpResponseObjectRedirect)({ url: urlTarget, statusCode: 301 }, urlWithoutBase);
|
|
356
362
|
const pageContextHttpResponse = { ...pageContextInit, httpResponse };
|
|
357
363
|
return pageContextHttpResponse;
|
|
358
364
|
}
|
|
@@ -396,10 +402,28 @@ async function handleAbortError(errAbort, pageContextsFromRewrite, pageContextIn
|
|
|
396
402
|
...pageContextInit,
|
|
397
403
|
...pageContextAbort
|
|
398
404
|
};
|
|
399
|
-
const httpResponse = (0, createHttpResponseObject_js_1.createHttpResponseObjectRedirect)(pageContextAbort._urlRedirect,
|
|
405
|
+
const httpResponse = (0, createHttpResponseObject_js_1.createHttpResponseObjectRedirect)(pageContextAbort._urlRedirect, (() => {
|
|
406
|
+
const { pathname, searchOriginal } = pageContextNominalPageInit.urlParsed;
|
|
407
|
+
const urlLogical = (0, utils_js_1.createUrlFromComponents)(null, pathname, searchOriginal,
|
|
408
|
+
// The server-side doesn't have access to the hash
|
|
409
|
+
null);
|
|
410
|
+
return urlLogical;
|
|
411
|
+
})());
|
|
400
412
|
(0, utils_js_1.objectAssign)(pageContextReturn, { httpResponse });
|
|
401
413
|
return { pageContextReturn };
|
|
402
414
|
}
|
|
403
415
|
(0, utils_js_1.assert)(pageContextAbort.abortStatusCode);
|
|
404
416
|
return { pageContextAbort };
|
|
405
417
|
}
|
|
418
|
+
function checkBaseUrl(pageContextInit, httpRequestId) {
|
|
419
|
+
const { baseServer } = (0, globalContext_js_1.getGlobalContext)();
|
|
420
|
+
const { urlOriginal } = pageContextInit;
|
|
421
|
+
const { urlWithoutPageContextRequestSuffix } = (0, handlePageContextRequestUrl_js_1.handlePageContextRequestUrl)(urlOriginal);
|
|
422
|
+
const { hasBaseServer } = (0, utils_js_1.parseUrl)(urlWithoutPageContextRequestSuffix, baseServer);
|
|
423
|
+
if (!hasBaseServer) {
|
|
424
|
+
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`${getRequestInfoMessage(urlOriginal)} skipped because URL ${picocolors_1.default.bold(urlOriginal)} doesn't start with Base URL ${picocolors_1.default.bold(baseServer)} (https://vike.dev/base-url)`, httpRequestId, 'info');
|
|
425
|
+
const pageContextHttpResponseNull = getPageContextHttpResponseNull(pageContextInit);
|
|
426
|
+
return pageContextHttpResponseNull;
|
|
427
|
+
}
|
|
428
|
+
return null;
|
|
429
|
+
}
|
|
@@ -5,7 +5,7 @@ const utils_js_1 = require("../utils.js");
|
|
|
5
5
|
const assert_exports_old_design_js_1 = require("./assert_exports_old_design.js");
|
|
6
6
|
const getPageFileObject_js_1 = require("./getPageFileObject.js");
|
|
7
7
|
const fileTypes_js_1 = require("./fileTypes.js");
|
|
8
|
-
const
|
|
8
|
+
const assertPageConfigsSerialized_js_1 = require("../page-configs/serialize/assertPageConfigsSerialized.js");
|
|
9
9
|
const parsePageConfigs_js_1 = require("../page-configs/serialize/parsePageConfigs.js");
|
|
10
10
|
function parseGlobResults(pageFilesExports) {
|
|
11
11
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'isGeneratedFile'));
|
|
@@ -21,8 +21,8 @@ function parseGlobResults(pageFilesExports) {
|
|
|
21
21
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageConfigsSerialized'));
|
|
22
22
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageConfigGlobalSerialized'));
|
|
23
23
|
const { pageConfigsSerialized, pageConfigGlobalSerialized } = pageFilesExports;
|
|
24
|
-
(0,
|
|
25
|
-
(0,
|
|
24
|
+
(0, assertPageConfigsSerialized_js_1.assertPageConfigsSerialized)(pageConfigsSerialized);
|
|
25
|
+
(0, assertPageConfigsSerialized_js_1.assertPageConfigGlobalSerialized)(pageConfigGlobalSerialized);
|
|
26
26
|
const { pageConfigs, pageConfigGlobal } = (0, parsePageConfigs_js_1.parsePageConfigs)(pageConfigsSerialized, pageConfigGlobalSerialized);
|
|
27
27
|
const pageFilesMap = {};
|
|
28
28
|
parseGlobResult(pageFilesExports.pageFilesLazy).forEach(({ filePath, pageFile, globValue }) => {
|
|
@@ -14,8 +14,8 @@ function isUserHookError(err) {
|
|
|
14
14
|
return globalObject.userHookErrors.get(err) ?? false;
|
|
15
15
|
}
|
|
16
16
|
exports.isUserHookError = isUserHookError;
|
|
17
|
-
function executeHook(
|
|
18
|
-
const { timeoutErr, timeoutWarn } =
|
|
17
|
+
function executeHook(hookFnCaller, hook) {
|
|
18
|
+
const { hookName, hookFilePath, hookTimeout: { error: timeoutErr, warning: timeoutWarn } } = hook;
|
|
19
19
|
let resolve;
|
|
20
20
|
let reject;
|
|
21
21
|
const promise = new Promise((resolve_, reject_) => {
|
|
@@ -29,19 +29,23 @@ function executeHook(hookFn, hookName, hookFilePath) {
|
|
|
29
29
|
};
|
|
30
30
|
});
|
|
31
31
|
const clearTimeouts = () => {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
if (currentTimeoutWarn)
|
|
33
|
+
clearTimeout(currentTimeoutWarn);
|
|
34
|
+
if (currentTimeoutErr)
|
|
35
|
+
clearTimeout(currentTimeoutErr);
|
|
34
36
|
};
|
|
35
|
-
const
|
|
36
|
-
(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
const currentTimeoutWarn = isNotDisabled(timeoutWarn) &&
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
(0, assert_js_1.assertWarning)(false, `The ${hookName}() hook defined by ${hookFilePath} is slow: it's taking more than ${(0, humanizeTime_js_1.humanizeTime)(timeoutWarn)} (https://vike.dev/hooksTimeout)`, { onlyOnce: false });
|
|
40
|
+
}, timeoutWarn);
|
|
41
|
+
const currentTimeoutErr = isNotDisabled(timeoutErr) &&
|
|
42
|
+
setTimeout(() => {
|
|
43
|
+
const err = (0, assert_js_1.getProjectError)(`The ${hookName}() hook defined by ${hookFilePath} timed out: it didn't finish after ${(0, humanizeTime_js_1.humanizeTime)(timeoutErr)} (https://vike.dev/hooksTimeout)`);
|
|
44
|
+
reject(err);
|
|
45
|
+
}, timeoutErr);
|
|
42
46
|
(async () => {
|
|
43
47
|
try {
|
|
44
|
-
const ret = await
|
|
48
|
+
const ret = await hookFnCaller();
|
|
45
49
|
resolve(ret);
|
|
46
50
|
}
|
|
47
51
|
catch (err) {
|
|
@@ -54,21 +58,6 @@ function executeHook(hookFn, hookName, hookFilePath) {
|
|
|
54
58
|
return promise;
|
|
55
59
|
}
|
|
56
60
|
exports.executeHook = executeHook;
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
timeoutErr: 5 * 1000,
|
|
61
|
-
timeoutWarn: 1 * 1000
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
if (hookName === 'onBeforePrerender') {
|
|
65
|
-
return {
|
|
66
|
-
timeoutErr: 10 * 60 * 1000,
|
|
67
|
-
timeoutWarn: 30 * 1000
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
return {
|
|
71
|
-
timeoutErr: 40 * 1000,
|
|
72
|
-
timeoutWarn: 4 * 1000
|
|
73
|
-
};
|
|
61
|
+
function isNotDisabled(timeout) {
|
|
62
|
+
return !!timeout && timeout !== Infinity;
|
|
74
63
|
}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
6
|
+
exports.getHookTimeoutDefault = exports.assertHook = exports.getHookFromPageConfigGlobal = exports.getHookFromPageConfig = exports.getHook = void 0;
|
|
7
|
+
const helpers_js_1 = require("../page-configs/helpers.js");
|
|
4
8
|
const utils_js_1 = require("../utils.js");
|
|
9
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
5
10
|
function getHook(pageContext, hookName) {
|
|
6
11
|
if (!(hookName in pageContext.exports)) {
|
|
7
12
|
return null;
|
|
8
13
|
}
|
|
14
|
+
const { hooksTimeout } = pageContext.config;
|
|
15
|
+
const hookTimeout = getHookTimeout(hooksTimeout, hookName);
|
|
9
16
|
const hookFn = pageContext.exports[hookName];
|
|
10
17
|
const file = pageContext.exportsAll[hookName][0];
|
|
11
18
|
(0, utils_js_1.assert)(file.exportValue === hookFn);
|
|
@@ -15,9 +22,41 @@ function getHook(pageContext, hookName) {
|
|
|
15
22
|
(0, utils_js_1.assert)(hookFilePath);
|
|
16
23
|
(0, utils_js_1.assert)(!hookFilePath.endsWith(' '));
|
|
17
24
|
assertHookFn(hookFn, { hookName, hookFilePath });
|
|
18
|
-
return { hookFn, hookName, hookFilePath };
|
|
25
|
+
return { hookFn, hookName, hookFilePath, hookTimeout };
|
|
19
26
|
}
|
|
20
27
|
exports.getHook = getHook;
|
|
28
|
+
function getHookFromPageConfig(pageConfig, hookName) {
|
|
29
|
+
const configValue = (0, helpers_js_1.getConfigValue)(pageConfig, hookName);
|
|
30
|
+
const hooksTimeout = (0, helpers_js_1.getConfigValue)(pageConfig, 'hooksTimeout')?.value;
|
|
31
|
+
if (!configValue)
|
|
32
|
+
return null;
|
|
33
|
+
const hookFn = configValue.value;
|
|
34
|
+
if (!hookFn)
|
|
35
|
+
return null;
|
|
36
|
+
const hookFilePath = (0, helpers_js_1.getHookFilePathToShowToUser)(configValue);
|
|
37
|
+
// hook isn't a computed nor a cumulative config => definedAt should always be defined
|
|
38
|
+
(0, utils_js_1.assert)(hookFilePath);
|
|
39
|
+
assertHookFn(hookFn, { hookName, hookFilePath });
|
|
40
|
+
const hookTimeout = getHookTimeout(hooksTimeout, hookName);
|
|
41
|
+
return { hookFn, hookName, hookFilePath, hookTimeout };
|
|
42
|
+
}
|
|
43
|
+
exports.getHookFromPageConfig = getHookFromPageConfig;
|
|
44
|
+
function getHookFromPageConfigGlobal(pageConfigGlobal, hookName) {
|
|
45
|
+
const configValue = pageConfigGlobal.configValues[hookName];
|
|
46
|
+
if (!configValue)
|
|
47
|
+
return null;
|
|
48
|
+
const hookFn = configValue.value;
|
|
49
|
+
if (!hookFn)
|
|
50
|
+
return null;
|
|
51
|
+
const hookFilePath = (0, helpers_js_1.getHookFilePathToShowToUser)(configValue);
|
|
52
|
+
// hook isn't a computed nor a cumulative config => definedAt should always be defined
|
|
53
|
+
(0, utils_js_1.assert)(hookFilePath);
|
|
54
|
+
assertHookFn(hookFn, { hookName, hookFilePath });
|
|
55
|
+
// We could use the global value of config.hooksTimeout but it requires some non-trivial refactoring
|
|
56
|
+
const hookTimeout = getHookTimeoutDefault(hookName);
|
|
57
|
+
return { hookFn, hookName, hookFilePath, hookTimeout };
|
|
58
|
+
}
|
|
59
|
+
exports.getHookFromPageConfigGlobal = getHookFromPageConfigGlobal;
|
|
21
60
|
function assertHook(pageContext, hookName) {
|
|
22
61
|
getHook(pageContext, hookName);
|
|
23
62
|
}
|
|
@@ -28,4 +67,66 @@ function assertHookFn(hookFn, { hookName, hookFilePath }) {
|
|
|
28
67
|
(0, utils_js_1.assertUsage)((0, utils_js_1.isCallable)(hookFn), `Hook ${hookName}() defined by ${hookFilePath} should be a function`);
|
|
29
68
|
(0, utils_js_1.checkType)(hookFn);
|
|
30
69
|
}
|
|
31
|
-
|
|
70
|
+
function getHookTimeout(hooksTimeoutProvidedByUser, hookName) {
|
|
71
|
+
const hooksTimeoutProvidedbyUserNormalized = getHooksTimeoutProvidedByUserNormalized(hooksTimeoutProvidedByUser);
|
|
72
|
+
if (hooksTimeoutProvidedbyUserNormalized === false)
|
|
73
|
+
return { error: false, warning: false };
|
|
74
|
+
const providedbyUser = hooksTimeoutProvidedbyUserNormalized[hookName];
|
|
75
|
+
const hookTimeout = getHookTimeoutDefault(hookName);
|
|
76
|
+
if (providedbyUser?.error !== undefined)
|
|
77
|
+
hookTimeout.error = providedbyUser.error;
|
|
78
|
+
if (providedbyUser?.warning !== undefined)
|
|
79
|
+
hookTimeout.warning = providedbyUser.warning;
|
|
80
|
+
return hookTimeout;
|
|
81
|
+
}
|
|
82
|
+
// Ideally this should be called only once and at build-time (to avoid bloating the client-side bundle), but we didn't implement any mechanism to valide config values at build-time yet
|
|
83
|
+
function getHooksTimeoutProvidedByUserNormalized(hooksTimeoutProvidedByUser) {
|
|
84
|
+
if (hooksTimeoutProvidedByUser === undefined)
|
|
85
|
+
return {};
|
|
86
|
+
if (hooksTimeoutProvidedByUser === false)
|
|
87
|
+
return false;
|
|
88
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(hooksTimeoutProvidedByUser), `Setting ${picocolors_1.default.cyan('hooksTimeout')} should be ${picocolors_1.default.cyan('false')} or an object`);
|
|
89
|
+
const hooksTimeoutProvidedByUserNormalized = {};
|
|
90
|
+
Object.entries(hooksTimeoutProvidedByUser).forEach(([hookName, hookTimeoutProvidedbyUser]) => {
|
|
91
|
+
if (hookTimeoutProvidedbyUser === false) {
|
|
92
|
+
hooksTimeoutProvidedByUserNormalized[hookName] = { error: false, warning: false };
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(hookTimeoutProvidedbyUser), `Setting ${picocolors_1.default.cyan(`hooksTimeout.${hookName}`)} should be ${picocolors_1.default.cyan('false')} or an object`);
|
|
96
|
+
const [error, warning] = ['error', 'warning'].map((timeoutName) => {
|
|
97
|
+
const timeoutVal = hookTimeoutProvidedbyUser[timeoutName];
|
|
98
|
+
if (timeoutVal === undefined || timeoutVal === false)
|
|
99
|
+
return timeoutVal;
|
|
100
|
+
const errPrefix = `Setting ${picocolors_1.default.cyan(`hooksTimeout.${hookName}.${timeoutName}`)} should be`;
|
|
101
|
+
(0, utils_js_1.assertUsage)(typeof timeoutVal === 'number', `${errPrefix} ${picocolors_1.default.cyan('false')} or a number`);
|
|
102
|
+
(0, utils_js_1.assertUsage)(timeoutVal > 0, `${errPrefix} a positive number`);
|
|
103
|
+
return timeoutVal;
|
|
104
|
+
});
|
|
105
|
+
hooksTimeoutProvidedByUserNormalized[hookName] = { error, warning };
|
|
106
|
+
});
|
|
107
|
+
return hooksTimeoutProvidedByUserNormalized;
|
|
108
|
+
}
|
|
109
|
+
function getHookTimeoutDefault(hookName) {
|
|
110
|
+
if (hookName === 'onBeforeRoute') {
|
|
111
|
+
return {
|
|
112
|
+
error: 5 * 1000,
|
|
113
|
+
warning: 1 * 1000
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
if (hookName === 'onPrerenderStart' ||
|
|
117
|
+
hookName === 'onBeforePrerenderStart' ||
|
|
118
|
+
// TODO/v1-release: remove
|
|
119
|
+
// Old V0.4 design hooks (https://vike.dev/migration/v1-design#renamed-hooks)
|
|
120
|
+
hookName === 'onBeforePrerender' ||
|
|
121
|
+
hookName === 'prerender') {
|
|
122
|
+
return {
|
|
123
|
+
error: 10 * 60 * 1000,
|
|
124
|
+
warning: 30 * 1000
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
error: 30 * 1000,
|
|
129
|
+
warning: 4 * 1000
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
exports.getHookTimeoutDefault = getHookTimeoutDefault;
|
|
@@ -10,7 +10,7 @@ const getExportPath_js_1 = require("../getExportPath.js");
|
|
|
10
10
|
function getConfigDefinedAtString(sentenceBegin, configName, { definedAt }) {
|
|
11
11
|
const definedAtString = getDefinedAtString(definedAt, configName);
|
|
12
12
|
const definedAtStr = definedAtString === 'internally' ? definedAtString : `at ${definedAtString}`;
|
|
13
|
-
let configNameStr = `${configName}${sentenceBegin === 'Hook' ? '()'
|
|
13
|
+
let configNameStr = `${configName}${ /*sentenceBegin === 'Hook' ? '()' :*/''}`;
|
|
14
14
|
const configDefinedAt = `${sentenceBegin} ${picocolors_1.default.cyan(configNameStr)} defined ${definedAtStr}`;
|
|
15
15
|
return configDefinedAt;
|
|
16
16
|
}
|
|
@@ -21,7 +21,7 @@ async function executeGuardHook(pageContext, prepareForUserConsumption) {
|
|
|
21
21
|
const res = prepareForUserConsumption(pageContext);
|
|
22
22
|
if (res)
|
|
23
23
|
pageContextForUserConsumption = res;
|
|
24
|
-
const hookResult = await (0, utils_js_1.executeHook)(() => guard(pageContextForUserConsumption),
|
|
24
|
+
const hookResult = await (0, utils_js_1.executeHook)(() => guard(pageContextForUserConsumption), hook);
|
|
25
25
|
(0, utils_js_1.assertUsage)(hookResult === undefined, `The guard() hook of ${hook.hookFilePath} returns a value, but guard() doesn't accept any return value`);
|
|
26
26
|
}
|
|
27
27
|
exports.executeGuardHook = executeGuardHook;
|
|
@@ -35,6 +35,7 @@ function findPageGuard(pageId, pageFilesAll) {
|
|
|
35
35
|
if (!hookFn)
|
|
36
36
|
return null;
|
|
37
37
|
const hookFilePath = filePath;
|
|
38
|
+
const hookTimeout = (0, getHook_js_1.getHookTimeoutDefault)('guard');
|
|
38
39
|
(0, utils_js_1.assertUsage)((0, utils_js_1.isCallable)(hookFn), `guard() defined by ${hookFilePath} should be a function`);
|
|
39
|
-
return { hookFn, hookName: 'guard', hookFilePath };
|
|
40
|
+
return { hookFn, hookName: 'guard', hookFilePath, hookTimeout };
|
|
40
41
|
}
|