vike 0.4.193 → 0.4.194
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/RenderErrorPage.js +1 -0
- package/__internal/setup.js +1 -0
- package/__internal.js +1 -0
- package/abort.js +1 -0
- package/cli.js +1 -0
- package/client/router.js +1 -0
- package/client.js +1 -0
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +2 -2
- package/dist/cjs/node/plugin/shared/addSsrMiddleware.js +4 -9
- package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +1 -13
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +2 -24
- package/dist/cjs/node/plugin/shared/loggerVite.js +0 -3
- package/dist/cjs/node/runtime/globalContext/loadImportBuild.js +2 -2
- package/dist/cjs/node/runtime/renderPage/assertArguments.js +3 -3
- package/dist/cjs/node/runtime/renderPage/{createHttpResponseObject.js → createHttpResponse.js} +16 -9
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +3 -5
- package/dist/cjs/node/runtime/renderPage/handleErrorWithoutErrorPage.js +4 -3
- package/dist/cjs/node/runtime/renderPage/inferMediaType.js +3 -0
- package/dist/cjs/node/runtime/renderPage/isConfigInvalid.js +4 -2
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -12
- package/dist/cjs/node/runtime/renderPage.js +59 -64
- package/dist/cjs/shared/page-configs/assertPlusFileExport.js +1 -2
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/isArray.js +1 -1
- package/dist/cjs/utils/parseUrl-extras.js +6 -1
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +2 -1
- package/dist/esm/node/plugin/plugins/importBuild/index.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +2 -2
- package/dist/esm/node/plugin/shared/addSsrMiddleware.js +4 -9
- package/dist/esm/node/plugin/shared/loggerNotProd/log.d.ts +0 -7
- package/dist/esm/node/plugin/shared/loggerNotProd/log.js +0 -12
- package/dist/esm/node/plugin/shared/loggerNotProd.d.ts +1 -7
- package/dist/esm/node/plugin/shared/loggerNotProd.js +2 -24
- package/dist/esm/node/plugin/shared/loggerVite.js +1 -4
- package/dist/esm/node/runtime/globalContext/loadImportBuild.js +1 -1
- package/dist/esm/node/runtime/renderPage/assertArguments.js +3 -3
- package/dist/esm/node/runtime/renderPage/{createHttpResponseObject.d.ts → createHttpResponse.d.ts} +9 -5
- package/dist/esm/node/runtime/renderPage/{createHttpResponseObject.js → createHttpResponse.js} +15 -8
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +3 -5
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.js +4 -3
- package/dist/esm/node/runtime/renderPage/inferMediaType.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/inferMediaType.js +3 -0
- package/dist/esm/node/runtime/renderPage/isConfigInvalid.d.ts +6 -2
- package/dist/esm/node/runtime/renderPage/isConfigInvalid.js +6 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +5 -11
- package/dist/esm/node/runtime/renderPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage.js +59 -64
- package/dist/esm/shared/page-configs/assertPlusFileExport.js +1 -2
- package/dist/esm/shared/route/abort.d.ts +3 -3
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/isArray.js +1 -1
- package/dist/esm/utils/parseUrl-extras.d.ts +2 -0
- package/dist/esm/utils/parseUrl-extras.js +5 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +66 -66
- package/plugin.js +1 -0
- package/prerender.js +1 -0
- package/routing.js +1 -0
- package/server.js +1 -0
package/dist/esm/node/runtime/renderPage/{createHttpResponseObject.d.ts → createHttpResponse.d.ts}
RENAMED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createHttpResponse };
|
|
2
2
|
export { createHttpResponsePageContextJson };
|
|
3
|
-
export {
|
|
3
|
+
export { createHttpResponseError };
|
|
4
|
+
export { createHttpResponseRedirect };
|
|
5
|
+
export { createHttpResponseFavicon404 };
|
|
4
6
|
export type { HttpResponse };
|
|
5
7
|
import type { GetPageAssets } from './getPageAssets.js';
|
|
6
8
|
import type { HtmlRender } from '../html/renderHtml.js';
|
|
@@ -16,13 +18,15 @@ type HttpResponse = {
|
|
|
16
18
|
/** **Deprecated**: use `headers` instead, see https://vike.dev/migration/0.4.134 */
|
|
17
19
|
contentType: 'application/json' | 'text/html;charset=utf-8';
|
|
18
20
|
} & HttpResponseBody;
|
|
19
|
-
declare function
|
|
21
|
+
declare function createHttpResponse(htmlRender: HtmlRender, renderHook: null | RenderHook, pageContext: {
|
|
20
22
|
_pageId: null | string;
|
|
21
23
|
is404: null | boolean;
|
|
22
24
|
errorWhileRendering: null | Error;
|
|
23
25
|
__getPageAssets: GetPageAssets;
|
|
24
26
|
_pageConfigs: PageConfigRuntime[];
|
|
25
27
|
abortStatusCode?: AbortStatusCode;
|
|
26
|
-
}): Promise<HttpResponse
|
|
28
|
+
}): Promise<HttpResponse>;
|
|
29
|
+
declare function createHttpResponseFavicon404(): HttpResponse;
|
|
30
|
+
declare function createHttpResponseError(): HttpResponse;
|
|
27
31
|
declare function createHttpResponsePageContextJson(pageContextSerialized: string): Promise<HttpResponse>;
|
|
28
|
-
declare function
|
|
32
|
+
declare function createHttpResponseRedirect({ url, statusCode }: UrlRedirect, urlLogical: string): HttpResponse;
|
package/dist/esm/node/runtime/renderPage/{createHttpResponseObject.js → createHttpResponse.js}
RENAMED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createHttpResponse };
|
|
2
2
|
export { createHttpResponsePageContextJson };
|
|
3
|
-
export {
|
|
3
|
+
export { createHttpResponseError };
|
|
4
|
+
export { createHttpResponseRedirect };
|
|
5
|
+
export { createHttpResponseFavicon404 };
|
|
4
6
|
import { assert, assertWarning } from '../utils.js';
|
|
5
7
|
import { isErrorPage } from '../../../shared/error-page.js';
|
|
6
8
|
import { getHttpResponseBody, getHttpResponseBodyStreamHandlers } from './getHttpResponseBody.js';
|
|
7
9
|
import { getEarlyHints } from './getEarlyHints.js';
|
|
8
10
|
import { getCacheControl } from './createHttpResponseObject/getCacheControl.js';
|
|
9
11
|
import { assertNoInfiniteHttpRedirect } from './createHttpResponseObject/assertNoInfiniteHttpRedirect.js';
|
|
10
|
-
async function
|
|
11
|
-
if (htmlRender === null) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
12
|
+
async function createHttpResponse(htmlRender, renderHook, pageContext) {
|
|
14
13
|
let statusCode = pageContext.abortStatusCode;
|
|
15
14
|
if (!statusCode) {
|
|
16
15
|
const isError = !pageContext._pageId || isErrorPage(pageContext._pageId, pageContext._pageConfigs);
|
|
@@ -35,11 +34,19 @@ async function createHttpResponseObject(htmlRender, renderHook, pageContext) {
|
|
|
35
34
|
}
|
|
36
35
|
return getHttpResponse(statusCode, 'text/html;charset=utf-8', headers, htmlRender, earlyHints, renderHook);
|
|
37
36
|
}
|
|
37
|
+
function createHttpResponseFavicon404() {
|
|
38
|
+
const httpResponse = getHttpResponse(404, 'text/html;charset=utf-8', [], "<p>No favicon.ico found.</p><script>console.log('This HTTP response was generated by Vike.')</script>");
|
|
39
|
+
return httpResponse;
|
|
40
|
+
}
|
|
41
|
+
function createHttpResponseError() {
|
|
42
|
+
const httpResponse = getHttpResponse(500, 'text/html;charset=utf-8', [], "<p>An error occurred.</p><script>console.log('This HTTP response was generated by Vike. This response is used instead of rendering the error page (https://vike.dev/error-page), either because there isn't error page or because an error occurred while rendering the error page.')</script>");
|
|
43
|
+
return httpResponse;
|
|
44
|
+
}
|
|
38
45
|
async function createHttpResponsePageContextJson(pageContextSerialized) {
|
|
39
46
|
const httpResponse = getHttpResponse(200, 'application/json', [], pageContextSerialized, [], null);
|
|
40
47
|
return httpResponse;
|
|
41
48
|
}
|
|
42
|
-
function
|
|
49
|
+
function createHttpResponseRedirect({ url, statusCode },
|
|
43
50
|
// The URL we assume the redirect to be logically based on
|
|
44
51
|
urlLogical) {
|
|
45
52
|
assertNoInfiniteHttpRedirect(url, urlLogical);
|
|
@@ -50,7 +57,7 @@ urlLogical) {
|
|
|
50
57
|
return getHttpResponse(statusCode, 'text/html;charset=utf-8', headers,
|
|
51
58
|
// For bots / programmatic crawlig: show what's going on.
|
|
52
59
|
// For users: showing a blank page is probably better than a flickering text.
|
|
53
|
-
`<p style="display: none">Redirecting to ${url}</p>`);
|
|
60
|
+
`<p style="display: none">Redirecting to ${url}</p><script>console.log('This HTTP response was generated by Vike.')</script>`);
|
|
54
61
|
}
|
|
55
62
|
function getHttpResponse(statusCode, contentType, headers, htmlRender, earlyHints = [], renderHook = null) {
|
|
56
63
|
headers.push(['Content-Type', contentType]);
|
|
@@ -17,9 +17,6 @@ async function executeOnRenderHtmlHook(pageContext) {
|
|
|
17
17
|
const { documentHtml, pageContextProvidedByRenderHook, pageContextPromise, injectFilter } = processHookReturnValue(hookReturnValue, renderHook);
|
|
18
18
|
Object.assign(pageContext, pageContextProvidedByRenderHook);
|
|
19
19
|
objectAssign(pageContext, { _pageContextPromise: pageContextPromise });
|
|
20
|
-
if (documentHtml === null || documentHtml === undefined) {
|
|
21
|
-
return { htmlRender: null, renderHook };
|
|
22
|
-
}
|
|
23
20
|
const onErrorWhileStreaming = (err) => {
|
|
24
21
|
// Should the stream inject the following?
|
|
25
22
|
// ```
|
|
@@ -75,7 +72,7 @@ function getRenderHook(pageContext) {
|
|
|
75
72
|
return hookFound;
|
|
76
73
|
}
|
|
77
74
|
function processHookReturnValue(hookReturnValue, renderHook) {
|
|
78
|
-
let documentHtml
|
|
75
|
+
let documentHtml;
|
|
79
76
|
let pageContextPromise = null;
|
|
80
77
|
let pageContextProvidedByRenderHook = null;
|
|
81
78
|
let injectFilter = null;
|
|
@@ -102,7 +99,8 @@ function processHookReturnValue(hookReturnValue, renderHook) {
|
|
|
102
99
|
assertUsage(isCallable(hookReturnValue.injectFilter), 'injectFilter should be a function');
|
|
103
100
|
injectFilter = hookReturnValue.injectFilter;
|
|
104
101
|
}
|
|
105
|
-
|
|
102
|
+
assertUsage(hookReturnValue.documentHtml, `${errPrefix} returned an object that is missing the ${pc.code('documentHtml')} property.`);
|
|
103
|
+
{
|
|
106
104
|
let val = hookReturnValue.documentHtml;
|
|
107
105
|
const errBegin = `${errPrefix} returned ${pc.cyan('{ documentHtml }')}, but ${pc.cyan('documentHtml')}`;
|
|
108
106
|
if (typeof val === 'string') {
|
|
@@ -2,7 +2,7 @@ export { handleErrorWithoutErrorPage };
|
|
|
2
2
|
import { stringify } from '@brillout/json-serializer/stringify';
|
|
3
3
|
import { getGlobalContext } from '../globalContext.js';
|
|
4
4
|
import { assert, assertWarning, objectAssign } from '../utils.js';
|
|
5
|
-
import {
|
|
5
|
+
import { createHttpResponse, createHttpResponseError } from './createHttpResponse.js';
|
|
6
6
|
import pc from '@brillout/picocolors';
|
|
7
7
|
// When the user hasn't defined _error.page.js
|
|
8
8
|
async function handleErrorWithoutErrorPage(pageContext) {
|
|
@@ -13,13 +13,14 @@ async function handleErrorWithoutErrorPage(pageContext) {
|
|
|
13
13
|
warnMissingErrorPage(isV1);
|
|
14
14
|
}
|
|
15
15
|
if (!pageContext.isClientSideNavigation) {
|
|
16
|
-
|
|
16
|
+
const httpResponse = createHttpResponseError();
|
|
17
|
+
objectAssign(pageContext, { httpResponse });
|
|
17
18
|
return pageContext;
|
|
18
19
|
}
|
|
19
20
|
else {
|
|
20
21
|
const __getPageAssets = async () => [];
|
|
21
22
|
objectAssign(pageContext, { __getPageAssets });
|
|
22
|
-
const httpResponse = await
|
|
23
|
+
const httpResponse = await createHttpResponse(stringify({ serverSideError: true }), null, pageContext);
|
|
23
24
|
objectAssign(pageContext, { httpResponse });
|
|
24
25
|
return pageContext;
|
|
25
26
|
}
|
|
@@ -2,6 +2,6 @@ export { inferMediaType };
|
|
|
2
2
|
export type { MediaType };
|
|
3
3
|
type MediaType = null | {
|
|
4
4
|
assetType: 'image' | 'script' | 'font' | 'style' | 'audio' | 'video' | 'document' | 'fetch' | 'track' | 'worker' | 'embed' | 'object';
|
|
5
|
-
mediaType: 'text/javascript' | 'text/css' | 'image/jpeg' | 'image/png' | 'image/webp' | 'image/gif' | 'image/svg+xml' | 'font/ttf' | 'font/woff' | 'font/woff2' | 'video/mp4' | 'video/webm' | 'video/ogg' | 'video/mpeg' | 'video/x-msvideo' | 'video/quicktime' | 'audio/mpeg' | 'audio/wav' | 'audio/ogg' | 'audio/aac' | 'audio/midi' | 'audio/flac';
|
|
5
|
+
mediaType: 'text/javascript' | 'text/css' | 'image/avif' | 'image/jpeg' | 'image/png' | 'image/webp' | 'image/gif' | 'image/svg+xml' | 'font/ttf' | 'font/woff' | 'font/woff2' | 'video/mp4' | 'video/webm' | 'video/ogg' | 'video/mpeg' | 'video/x-msvideo' | 'video/quicktime' | 'audio/mpeg' | 'audio/wav' | 'audio/ogg' | 'audio/aac' | 'audio/midi' | 'audio/flac';
|
|
6
6
|
};
|
|
7
7
|
declare function inferMediaType(href: string): MediaType;
|
|
@@ -24,6 +24,9 @@ function inferMediaType(href) {
|
|
|
24
24
|
if (href.endsWith('.svg')) {
|
|
25
25
|
return { assetType: 'image', mediaType: 'image/svg+xml' };
|
|
26
26
|
}
|
|
27
|
+
if (href.endsWith('.avif')) {
|
|
28
|
+
return { assetType: 'image', mediaType: 'image/avif' };
|
|
29
|
+
}
|
|
27
30
|
// Fonts
|
|
28
31
|
if (href.endsWith('.ttf')) {
|
|
29
32
|
return { assetType: 'font', mediaType: 'font/ttf' };
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { isConfigInvalid };
|
|
2
|
+
export { isConfigInvalid_set };
|
|
3
|
+
declare let isConfigInvalid: false | {
|
|
4
|
+
err: unknown;
|
|
5
|
+
};
|
|
6
|
+
declare const isConfigInvalid_set: (val: typeof isConfigInvalid) => void;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { isConfigInvalid };
|
|
2
|
+
export { isConfigInvalid_set };
|
|
3
|
+
import { assert } from '../utils.js';
|
|
4
|
+
let isConfigInvalid;
|
|
5
|
+
const isConfigInvalid_set = (val) => {
|
|
6
|
+
assert(val === false || val.err);
|
|
3
7
|
isConfigInvalid = val;
|
|
4
8
|
};
|
|
@@ -8,13 +8,13 @@ export type { PageContextAfterRender };
|
|
|
8
8
|
export type { PageContextInitEnhanced };
|
|
9
9
|
import { type PageFile } from '../../../shared/getPageFiles.js';
|
|
10
10
|
import { type PageContextUrlInternal } from '../../../shared/getPageContextUrlComputed.js';
|
|
11
|
-
import { HttpResponse } from './
|
|
11
|
+
import { HttpResponse } from './createHttpResponse.js';
|
|
12
12
|
import { PageContext_loadUserFilesServerSide, type PageFiles } from './loadUserFilesServerSide.js';
|
|
13
13
|
import type { PageConfigRuntime, PageConfigGlobalRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
14
14
|
import { type PageRoutes } from '../../../shared/route/loadPageRoutes.js';
|
|
15
15
|
import type { Hook } from '../../../shared/hooks/getHook.js';
|
|
16
16
|
type PageContextAfterRender = {
|
|
17
|
-
httpResponse:
|
|
17
|
+
httpResponse: HttpResponse;
|
|
18
18
|
errorWhileRendering: null | Error;
|
|
19
19
|
};
|
|
20
20
|
declare function renderPageAlreadyRouted<PageContext extends {
|
|
@@ -10,7 +10,7 @@ import { assert, assertUsage, assertWarning, hasProp, normalizeHeaders, objectAs
|
|
|
10
10
|
import { serializePageContextClientSide } from '../html/serializePageContextClientSide.js';
|
|
11
11
|
import { getPageContextUrlComputed } from '../../../shared/getPageContextUrlComputed.js';
|
|
12
12
|
import { getGlobalContext } from '../globalContext.js';
|
|
13
|
-
import {
|
|
13
|
+
import { createHttpResponse, createHttpResponsePageContextJson } from './createHttpResponse.js';
|
|
14
14
|
import { loadUserFilesServerSide } from './loadUserFilesServerSide.js';
|
|
15
15
|
import { executeOnRenderHtmlHook } from './executeOnRenderHtmlHook.js';
|
|
16
16
|
import { executeOnBeforeRenderAndDataHooks } from './executeOnBeforeRenderAndDataHooks.js';
|
|
@@ -56,16 +56,10 @@ async function renderPageAlreadyRouted(pageContext) {
|
|
|
56
56
|
return pageContext;
|
|
57
57
|
}
|
|
58
58
|
const renderHookResult = await executeOnRenderHtmlHook(pageContext);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
else {
|
|
64
|
-
const { htmlRender, renderHook } = renderHookResult;
|
|
65
|
-
const httpResponse = await createHttpResponseObject(htmlRender, renderHook, pageContext);
|
|
66
|
-
objectAssign(pageContext, { httpResponse });
|
|
67
|
-
return pageContext;
|
|
68
|
-
}
|
|
59
|
+
const { htmlRender, renderHook } = renderHookResult;
|
|
60
|
+
const httpResponse = await createHttpResponse(htmlRender, renderHook, pageContext);
|
|
61
|
+
objectAssign(pageContext, { httpResponse });
|
|
62
|
+
return pageContext;
|
|
69
63
|
}
|
|
70
64
|
async function prerenderPage(pageContext) {
|
|
71
65
|
objectAssign(pageContext, {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { renderPage };
|
|
2
2
|
export { renderPage_addWrapper };
|
|
3
|
-
import { HttpResponse } from './renderPage/
|
|
3
|
+
import { HttpResponse } from './renderPage/createHttpResponse.js';
|
|
4
4
|
import type { PageContextServer } from '../../types/index.js';
|
|
5
5
|
declare let renderPage_wrapper: <PageContext>(_httpRequestId: number, ret: () => Promise<PageContext>) => Promise<{
|
|
6
6
|
pageContextReturn: Awaited<PageContext>;
|
|
@@ -12,5 +12,5 @@ declare function renderPage<PageContextUserAdded extends {}, PageContextInit ext
|
|
|
12
12
|
/** The URL of the HTTP request */
|
|
13
13
|
urlOriginal: string;
|
|
14
14
|
}>(pageContextInit: PageContextInit): Promise<PageContextInit & {
|
|
15
|
-
httpResponse: HttpResponse
|
|
15
|
+
httpResponse: HttpResponse;
|
|
16
16
|
} & Partial<PageContextServer & PageContextUserAdded>>;
|
|
@@ -2,11 +2,11 @@ export { renderPage };
|
|
|
2
2
|
export { renderPage_addWrapper };
|
|
3
3
|
import { getRenderContext, getPageContextInitEnhanced, renderPageAlreadyRouted } from './renderPage/renderPageAlreadyRouted.js';
|
|
4
4
|
import { route } from '../../shared/route/index.js';
|
|
5
|
-
import { assert, hasProp, objectAssign, isUrl, parseUrl, assertEnv, assertWarning, getGlobalObject, checkType, assertUsage, normalizeUrlPathname, removeBaseServer, modifyUrlPathname, prependBase, removeUrlOrigin, addUrlOrigin, createUrlFromComponents, isUri } from './utils.js';
|
|
5
|
+
import { assert, hasProp, objectAssign, isUrl, parseUrl, assertEnv, assertWarning, getGlobalObject, checkType, assertUsage, normalizeUrlPathname, removeBaseServer, modifyUrlPathname, prependBase, removeUrlOrigin, addUrlOrigin, createUrlFromComponents, isUri, getUrlPretty } from './utils.js';
|
|
6
6
|
import { assertNoInfiniteAbortLoop, getPageContextFromAllRewrites, isAbortError, logAbortErrorHandled } from '../../shared/route/abort.js';
|
|
7
7
|
import { getGlobalContext, initGlobalContext_renderPage } from './globalContext.js';
|
|
8
8
|
import { handlePageContextRequestUrl } from './renderPage/handlePageContextRequestUrl.js';
|
|
9
|
-
import {
|
|
9
|
+
import { createHttpResponseFavicon404, createHttpResponseRedirect, createHttpResponsePageContextJson, createHttpResponseError } from './renderPage/createHttpResponse.js';
|
|
10
10
|
import { logRuntimeError, logRuntimeInfo } from './renderPage/loggerRuntime.js';
|
|
11
11
|
import { isNewError } from './renderPage/isNewError.js';
|
|
12
12
|
import { assertArguments } from './renderPage/assertArguments.js';
|
|
@@ -19,8 +19,7 @@ import { handleErrorWithoutErrorPage } from './renderPage/handleErrorWithoutErro
|
|
|
19
19
|
import { loadUserFilesServerSide } from './renderPage/loadUserFilesServerSide.js';
|
|
20
20
|
import { resolveRedirects } from './renderPage/resolveRedirects.js';
|
|
21
21
|
const globalObject = getGlobalObject('runtime/renderPage.ts', {
|
|
22
|
-
httpRequestsCount: 0
|
|
23
|
-
pendingRequestsCount: 0
|
|
22
|
+
httpRequestsCount: 0
|
|
24
23
|
});
|
|
25
24
|
let renderPage_wrapper = async (_httpRequestId, ret) => ({
|
|
26
25
|
pageContextReturn: await ret()
|
|
@@ -31,32 +30,34 @@ const renderPage_addWrapper = (wrapper) => {
|
|
|
31
30
|
// `renderPage()` calls `renderPageNominal()` while ensuring that errors are `console.error(err)` instead of `throw err`, so that Vike never triggers a server shut down. (Throwing an error in an Express.js middleware shuts down the whole Express.js server.)
|
|
32
31
|
async function renderPage(pageContextInit) {
|
|
33
32
|
assertArguments(...arguments);
|
|
34
|
-
assert(hasProp(pageContextInit, 'urlOriginal', 'string'));
|
|
33
|
+
assert(hasProp(pageContextInit, 'urlOriginal', 'string')); // assertUsage() already implemented at assertArguments()
|
|
35
34
|
assertEnv();
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
assertIsUrl(pageContextInit.urlOriginal);
|
|
36
|
+
const urlPathnameWithBase = parseUrl(pageContextInit.urlOriginal, '/').pathname;
|
|
37
|
+
assertIsNotViteRequest(urlPathnameWithBase, pageContextInit.urlOriginal);
|
|
38
|
+
if (urlPathnameWithBase.endsWith('/favicon.ico'))
|
|
39
|
+
return getPageContextHttpResponseFavicon404(pageContextInit);
|
|
41
40
|
const httpRequestId = getRequestId();
|
|
42
|
-
const
|
|
43
|
-
logHttpRequest(
|
|
44
|
-
globalObject.pendingRequestsCount++;
|
|
41
|
+
const urlOriginalPretty = getUrlPretty(pageContextInit.urlOriginal);
|
|
42
|
+
logHttpRequest(urlOriginalPretty, httpRequestId);
|
|
45
43
|
const { pageContextReturn } = await renderPage_wrapper(httpRequestId, () => renderPageAndPrepare(pageContextInit, httpRequestId));
|
|
46
|
-
logHttpResponse(
|
|
47
|
-
globalObject.pendingRequestsCount--;
|
|
44
|
+
logHttpResponse(urlOriginalPretty, httpRequestId, pageContextReturn);
|
|
48
45
|
checkType(pageContextReturn);
|
|
46
|
+
assert(pageContextReturn.httpResponse);
|
|
49
47
|
return pageContextReturn;
|
|
50
48
|
}
|
|
51
49
|
async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
52
50
|
// Invalid config
|
|
53
|
-
const handleInvalidConfig = () => {
|
|
51
|
+
const handleInvalidConfig = (err) => {
|
|
54
52
|
logRuntimeInfo?.(pc.bold(pc.red('Error while loading a Vike config file, see error above.')), httpRequestId, 'error');
|
|
55
|
-
const
|
|
56
|
-
return
|
|
53
|
+
const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit);
|
|
54
|
+
return pageContextWithError;
|
|
57
55
|
};
|
|
58
56
|
if (isConfigInvalid) {
|
|
59
|
-
|
|
57
|
+
if (1 < 2 // Make TS happy
|
|
58
|
+
) {
|
|
59
|
+
return handleInvalidConfig(isConfigInvalid.err);
|
|
60
|
+
}
|
|
60
61
|
}
|
|
61
62
|
// Prepare context
|
|
62
63
|
let renderContext;
|
|
@@ -69,21 +70,17 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
|
69
70
|
// initGlobalContext_renderPage() and getRenderContext() don't call any user hooks => err isn't thrown from user code.
|
|
70
71
|
assert(!isAbortError(err));
|
|
71
72
|
logRuntimeError(err, httpRequestId);
|
|
72
|
-
const
|
|
73
|
-
return
|
|
73
|
+
const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit);
|
|
74
|
+
return pageContextWithError;
|
|
74
75
|
}
|
|
75
76
|
if (isConfigInvalid) {
|
|
76
|
-
return handleInvalidConfig();
|
|
77
|
+
return handleInvalidConfig(isConfigInvalid.err);
|
|
77
78
|
}
|
|
78
79
|
else {
|
|
79
80
|
// From now on, renderContext.pageConfigs contains all the configuration data; getVikeConfig() isn't called anymore for this request
|
|
80
81
|
}
|
|
81
82
|
// Check Base URL
|
|
82
|
-
|
|
83
|
-
const pageContextHttpResponse = checkBaseUrl(pageContextInit, httpRequestId);
|
|
84
|
-
if (pageContextHttpResponse)
|
|
85
|
-
return pageContextHttpResponse;
|
|
86
|
-
}
|
|
83
|
+
assertBaseUrl(pageContextInit);
|
|
87
84
|
// Normalize URL
|
|
88
85
|
{
|
|
89
86
|
const pageContextHttpResponse = normalizeUrl(pageContextInit, httpRequestId);
|
|
@@ -179,8 +176,8 @@ async function renderPageAlreadyPrepared(pageContextInit, httpRequestId, renderC
|
|
|
179
176
|
if (!handled.pageContextReturn) {
|
|
180
177
|
const pageContextAbort = errErrorPage._pageContextAbort;
|
|
181
178
|
assertWarning(false, `Failed to render error page because ${pc.cyan(pageContextAbort._abortCall)} was called: make sure ${pc.cyan(pageContextAbort._abortCaller)} doesn't occur while the error page is being rendered.`, { onlyOnce: false });
|
|
182
|
-
const
|
|
183
|
-
return
|
|
179
|
+
const pageContextHttpWithError = getPageContextHttpResponseError(errNominalPage, pageContextInit);
|
|
180
|
+
return pageContextHttpWithError;
|
|
184
181
|
}
|
|
185
182
|
// `throw redirect()` / `throw render(url)`
|
|
186
183
|
return handled.pageContextReturn;
|
|
@@ -188,20 +185,19 @@ async function renderPageAlreadyPrepared(pageContextInit, httpRequestId, renderC
|
|
|
188
185
|
if (isNewError(errErrorPage, errNominalPage)) {
|
|
189
186
|
logRuntimeError(errErrorPage, httpRequestId);
|
|
190
187
|
}
|
|
191
|
-
const
|
|
192
|
-
return
|
|
188
|
+
const pageContextWithError = getPageContextHttpResponseError(errNominalPage, pageContextInit);
|
|
189
|
+
return pageContextWithError;
|
|
193
190
|
}
|
|
194
191
|
return pageContextErrorPage;
|
|
195
192
|
}
|
|
196
193
|
}
|
|
197
194
|
function logHttpRequest(urlOriginal, httpRequestId) {
|
|
198
|
-
|
|
199
|
-
logRuntimeInfo?.(getRequestInfoMessage(urlOriginal), httpRequestId, 'info', clearErrors);
|
|
195
|
+
logRuntimeInfo?.(getRequestInfoMessage(urlOriginal), httpRequestId, 'info');
|
|
200
196
|
}
|
|
201
197
|
function getRequestInfoMessage(urlOriginal) {
|
|
202
198
|
return `HTTP request: ${prettyUrl(urlOriginal)}`;
|
|
203
199
|
}
|
|
204
|
-
function logHttpResponse(
|
|
200
|
+
function logHttpResponse(urlOriginalPretty, httpRequestId, pageContextReturn) {
|
|
205
201
|
const statusCode = pageContextReturn.httpResponse?.statusCode ?? null;
|
|
206
202
|
let msg;
|
|
207
203
|
let isNominal;
|
|
@@ -212,10 +208,10 @@ function logHttpResponse(urlOriginal, httpRequestId, pageContextReturn) {
|
|
|
212
208
|
// - URL doesn't include Base URL
|
|
213
209
|
// - Can we abort earlier so that `logHttpResponse()` and `logHttpRequest()` aren't even called?
|
|
214
210
|
// - Error loading a Vike config file
|
|
215
|
-
// - We should show `HTTP response ${
|
|
211
|
+
// - We should show `HTTP response ${urlOriginalPretty} ERR` instead.
|
|
216
212
|
// - Maybe we can/should make the error available at pageContext.errorWhileRendering
|
|
217
213
|
assert(errorWhileRendering === null || errorWhileRendering === undefined);
|
|
218
|
-
msg = `HTTP response ${prettyUrl(
|
|
214
|
+
msg = `HTTP response ${prettyUrl(urlOriginalPretty)} ${pc.dim('null')}`;
|
|
219
215
|
// Erroneous value (it shoud sometimes be `false`) but it's fine as it doesn't seem to have much of an impact.
|
|
220
216
|
isNominal = true;
|
|
221
217
|
}
|
|
@@ -233,28 +229,30 @@ function logHttpResponse(urlOriginal, httpRequestId, pageContextReturn) {
|
|
|
233
229
|
.find((header) => header[0] === 'Location');
|
|
234
230
|
assert(headerRedirect);
|
|
235
231
|
const urlRedirect = headerRedirect[1];
|
|
236
|
-
|
|
232
|
+
urlOriginalPretty = urlRedirect;
|
|
237
233
|
}
|
|
238
|
-
msg = `HTTP ${type} ${prettyUrl(
|
|
234
|
+
msg = `HTTP ${type} ${prettyUrl(urlOriginalPretty)} ${color(statusCode ?? 'ERR')}`;
|
|
239
235
|
}
|
|
240
236
|
}
|
|
241
237
|
logRuntimeInfo?.(msg, httpRequestId, isNominal ? 'info' : 'error');
|
|
242
238
|
}
|
|
243
|
-
function
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
239
|
+
function getPageContextHttpResponseError(err, pageContextInit) {
|
|
240
|
+
const pageContextWithError = createPageContext(pageContextInit);
|
|
241
|
+
const httpResponse = createHttpResponseError();
|
|
242
|
+
objectAssign(pageContextWithError, {
|
|
243
|
+
httpResponse,
|
|
247
244
|
errorWhileRendering: err
|
|
248
245
|
});
|
|
249
|
-
return
|
|
246
|
+
return pageContextWithError;
|
|
250
247
|
}
|
|
251
|
-
function
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
248
|
+
function getPageContextHttpResponseFavicon404(pageContextInit) {
|
|
249
|
+
const pageContext = createPageContext(pageContextInit);
|
|
250
|
+
const httpResponse = createHttpResponseFavicon404();
|
|
251
|
+
objectAssign(pageContext, {
|
|
252
|
+
httpResponse
|
|
256
253
|
});
|
|
257
|
-
|
|
254
|
+
checkType(pageContext);
|
|
255
|
+
return pageContext;
|
|
258
256
|
}
|
|
259
257
|
function createPageContext(pageContextInit) {
|
|
260
258
|
const pageContext = {
|
|
@@ -325,10 +323,12 @@ function getRequestId() {
|
|
|
325
323
|
assert(httpRequestId >= 1);
|
|
326
324
|
return httpRequestId;
|
|
327
325
|
}
|
|
328
|
-
function
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
326
|
+
function assertIsUrl(urlOriginal) {
|
|
327
|
+
assertUsage(isUrl(urlOriginal), `${pc.code('renderPage(pageContextInit)')} (https://vike.dev/renderPage) called with ${pc.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which isn't a valid URL.`);
|
|
328
|
+
}
|
|
329
|
+
function assertIsNotViteRequest(urlPathname, urlOriginal) {
|
|
330
|
+
const isViteRequest = urlPathname.startsWith('/@vite/client') || urlPathname.startsWith('/@fs/') || urlPathname.startsWith('/__vite_ping');
|
|
331
|
+
assertUsage(!isViteRequest, `${pc.code('renderPage(pageContextInit)')} (https://vike.dev/renderPage) called with ${pc.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which is unexpected because this URL 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`);
|
|
332
332
|
}
|
|
333
333
|
function normalizeUrl(pageContextInit, httpRequestId) {
|
|
334
334
|
const { trailingSlash, disableUrlNormalization, baseServer } = getGlobalContext();
|
|
@@ -342,7 +342,7 @@ function normalizeUrl(pageContextInit, httpRequestId) {
|
|
|
342
342
|
if (!urlNormalized)
|
|
343
343
|
return null;
|
|
344
344
|
logRuntimeInfo?.(`URL normalized from ${pc.cyan(urlOriginal)} to ${pc.cyan(urlNormalized)} (https://vike.dev/url-normalization)`, httpRequestId, 'info');
|
|
345
|
-
const httpResponse =
|
|
345
|
+
const httpResponse = createHttpResponseRedirect({ url: urlNormalized, statusCode: 301 }, pageContextInit.urlOriginal);
|
|
346
346
|
const pageContextHttpResponse = createPageContext(pageContextInit);
|
|
347
347
|
objectAssign(pageContextHttpResponse, { httpResponse });
|
|
348
348
|
return pageContextHttpResponse;
|
|
@@ -378,7 +378,7 @@ function getPermanentRedirect(pageContextInit, httpRequestId) {
|
|
|
378
378
|
assert(urlTarget !== pageContextInit.urlOriginal);
|
|
379
379
|
}
|
|
380
380
|
logRuntimeInfo?.(`Permanent redirect defined by your config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
|
|
381
|
-
const httpResponse =
|
|
381
|
+
const httpResponse = createHttpResponseRedirect({ url: urlTarget, statusCode: 301 }, urlWithoutBase);
|
|
382
382
|
const pageContextHttpResponse = createPageContext(pageContextInit);
|
|
383
383
|
objectAssign(pageContextHttpResponse, { httpResponse });
|
|
384
384
|
return pageContextHttpResponse;
|
|
@@ -422,7 +422,7 @@ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageIn
|
|
|
422
422
|
if (pageContextAbort._urlRedirect) {
|
|
423
423
|
const pageContextReturn = createPageContext(pageContextInit);
|
|
424
424
|
objectAssign(pageContextReturn, pageContextAbort);
|
|
425
|
-
const httpResponse =
|
|
425
|
+
const httpResponse = createHttpResponseRedirect(pageContextAbort._urlRedirect, (() => {
|
|
426
426
|
const { pathname, searchOriginal } = pageContextNominalPageInit.urlParsed;
|
|
427
427
|
const urlLogical = createUrlFromComponents(null, pathname, searchOriginal,
|
|
428
428
|
// The server-side doesn't have access to the hash
|
|
@@ -435,18 +435,13 @@ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageIn
|
|
|
435
435
|
assert(pageContextAbort.abortStatusCode);
|
|
436
436
|
return { pageContextAbort };
|
|
437
437
|
}
|
|
438
|
-
function
|
|
438
|
+
function assertBaseUrl(pageContextInit) {
|
|
439
439
|
const { baseServer } = getGlobalContext();
|
|
440
440
|
const { urlOriginal } = pageContextInit;
|
|
441
441
|
const { urlWithoutPageContextRequestSuffix } = handlePageContextRequestUrl(urlOriginal);
|
|
442
442
|
const { hasBaseServer } = parseUrl(urlWithoutPageContextRequestSuffix, baseServer);
|
|
443
|
-
|
|
444
|
-
logRuntimeInfo?.(`${getRequestInfoMessage(urlOriginal)} skipped because URL ${prettyUrl(urlOriginal)} doesn't start with Base URL ${prettyUrl(baseServer)} (https://vike.dev/base-url)`, httpRequestId, 'info');
|
|
445
|
-
const pageContextHttpResponseNull = getPageContextHttpResponseNull(pageContextInit);
|
|
446
|
-
return pageContextHttpResponseNull;
|
|
447
|
-
}
|
|
448
|
-
return null;
|
|
443
|
+
assertUsage(hasBaseServer, `${pc.code('renderPage(pageContextInit)')} (https://vike.dev/renderPage) called with ${pc.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which doesn't start with Base URL ${prettyUrl(baseServer)} (https://vike.dev/base-url)`);
|
|
449
444
|
}
|
|
450
445
|
function prettyUrl(url) {
|
|
451
|
-
return pc.
|
|
446
|
+
return pc.code(decodeURI(url));
|
|
452
447
|
}
|
|
@@ -19,6 +19,7 @@ function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
|
|
|
19
19
|
}
|
|
20
20
|
const exportDefault = pc.code('export default');
|
|
21
21
|
const exportNamed = pc.code(`export { ${configName} }`);
|
|
22
|
+
assert(exportNamesValid.length <= 2);
|
|
22
23
|
if (exportNamesValid.length === 0) {
|
|
23
24
|
assertUsage(false, `${filePathToShowToUser} should have a ${exportNamed} or ${exportDefault}`);
|
|
24
25
|
}
|
|
@@ -27,8 +28,6 @@ function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
|
|
|
27
28
|
onlyOnce: true
|
|
28
29
|
});
|
|
29
30
|
}
|
|
30
|
-
assert(exportNamesValid.length === 1);
|
|
31
|
-
assert(exportNamesInvalid.length > 0);
|
|
32
31
|
if (!TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext))) {
|
|
33
32
|
exportNamesInvalid.forEach((exportInvalid) => {
|
|
34
33
|
assertWarning(false, `${filePathToShowToUser} unexpected ${pc.cyan(`export { ${exportInvalid} }`)}`, {
|
|
@@ -43,9 +43,9 @@ declare function redirect(url: string, statusCode?: 301 | 302): AbortRedirect;
|
|
|
43
43
|
* `404` Not Found
|
|
44
44
|
* `410` Gone (use this instead of `404` if the page existed in the past, see https://github.com/vikejs/vike/issues/1097#issuecomment-1695260887)
|
|
45
45
|
* `429` Too Many Requests (rate limiting)
|
|
46
|
-
* `500` Internal Server Error (
|
|
47
|
-
* `503` Service Unavailable (server is overloaded, a third-party API isn't responding)
|
|
48
|
-
* @param abortReason Sets `pageContext.abortReason` which is used by the error page to show a message to the user, see https://vike.dev/error-page
|
|
46
|
+
* `500` Internal Server Error (your client or server has a bug)
|
|
47
|
+
* `503` Service Unavailable (server is overloaded, or a third-party API isn't responding)
|
|
48
|
+
* @param abortReason Sets `pageContext.abortReason` which is usually used by the error page to show a message to the user, see https://vike.dev/error-page
|
|
49
49
|
*/
|
|
50
50
|
declare function render(abortStatusCode: 401 | 403 | 404 | 410 | 429 | 500 | 503, abortReason?: AbortReason): Error;
|
|
51
51
|
/**
|
|
@@ -3,7 +3,7 @@ export type { PageContextServer } from '../shared/types.js';
|
|
|
3
3
|
export type { PageContextClient } from '../shared/types.js';
|
|
4
4
|
export type { PageContextWithServerRouting } from '../shared/types.js';
|
|
5
5
|
export type { PageContextClientWithServerRouting } from '../shared/types.js';
|
|
6
|
-
export type { ConfigVitePluginServerEntry } from '@brillout/vite-plugin-server-entry/plugin
|
|
6
|
+
export type { ConfigVitePluginServerEntry } from '@brillout/vite-plugin-server-entry/plugin';
|
|
7
7
|
export type { PageContextBuiltInServer } from '../shared/types.js';
|
|
8
8
|
export type { PageContextBuiltInClientWithClientRouting } from '../shared/types.js';
|
|
9
9
|
export type { PageContextBuiltInClientWithServerRouting } from '../shared/types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.194";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.
|
|
2
|
+
export const PROJECT_VERSION = '0.4.194';
|
|
@@ -5,6 +5,7 @@ export { removeBaseServer };
|
|
|
5
5
|
export { modifyUrlPathname };
|
|
6
6
|
export { removeUrlOrigin };
|
|
7
7
|
export { addUrlOrigin };
|
|
8
|
+
export { getUrlPretty };
|
|
8
9
|
declare function prependBase(url: string, baseServer: string): string;
|
|
9
10
|
declare function removeBaseServer(url: string, baseServer: string): string;
|
|
10
11
|
declare function isBaseAssets(base: string): boolean;
|
|
@@ -15,3 +16,4 @@ declare function removeUrlOrigin(url: string): {
|
|
|
15
16
|
origin: string | null;
|
|
16
17
|
};
|
|
17
18
|
declare function addUrlOrigin(url: string, origin: string | null): string;
|
|
19
|
+
declare function getUrlPretty(url: string): string;
|
|
@@ -5,6 +5,7 @@ export { removeBaseServer };
|
|
|
5
5
|
export { modifyUrlPathname };
|
|
6
6
|
export { removeUrlOrigin };
|
|
7
7
|
export { addUrlOrigin };
|
|
8
|
+
export { getUrlPretty };
|
|
8
9
|
import { assertUrlComponents, createUrlFromComponents, isBaseServer, parseUrl } from './parseUrl.js';
|
|
9
10
|
import { assert } from './assert.js';
|
|
10
11
|
import { slice } from './slice.js';
|
|
@@ -100,3 +101,7 @@ function addUrlOrigin(url, origin) {
|
|
|
100
101
|
const urlModified = createUrlFromComponents(origin, pathnameOriginal, searchOriginal, hashOriginal);
|
|
101
102
|
return urlModified;
|
|
102
103
|
}
|
|
104
|
+
function getUrlPretty(url) {
|
|
105
|
+
const { urlModified } = removeUrlOrigin(url);
|
|
106
|
+
return urlModified;
|
|
107
|
+
}
|