vike 0.4.224-commit-f0d0f8a → 0.4.224-commit-00ed9fe
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/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +13 -5
- package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +2 -4
- package/dist/cjs/node/runtime/renderPage.js +6 -10
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/parseUrl-extras.js +1 -0
- package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.d.ts +3 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +14 -6
- package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +3 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse.js +2 -4
- package/dist/esm/node/runtime/renderPage.js +7 -11
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/parseUrl-extras.js +1 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
|
@@ -9,20 +9,28 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
9
9
|
const globalObject = (0, utils_js_1.getGlobalObject)('createHttpResponse/assertNoInfiniteHttpRedirect.ts', {
|
|
10
10
|
redirectGraph: {}
|
|
11
11
|
});
|
|
12
|
-
|
|
12
|
+
// It's too strict, see https://github.com/vikejs/vike/issues/1270#issuecomment-1820608999
|
|
13
|
+
// - Let's create a new setting `+doNotCatchInfiniteRedirect` if someone complains.
|
|
14
|
+
function assertNoInfiniteHttpRedirect(
|
|
15
|
+
// The exact URL that the user will be redirected to.
|
|
16
|
+
// - It includes the Base URL as well as the locale (i18n) base.
|
|
17
|
+
urlRedirectTarget,
|
|
18
|
+
// Rationale for checking against `pageContextInit.urlOriginal`: https://github.com/vikejs/vike/pull/2264#issuecomment-2713890263
|
|
19
|
+
pageContextInit) {
|
|
13
20
|
if (!urlRedirectTarget.startsWith('/')) {
|
|
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
|
|
21
|
+
// 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 (at least not in itself).
|
|
22
|
+
// - There isn't a reliable way to check whether the redirect points to an external origin or the same origin; we hope/assume the user sets the URL without origin.
|
|
16
23
|
// ```js
|
|
17
24
|
// // For same-origin, the user usually/hopefully passes a URL without origin
|
|
18
25
|
// renderPage({ urlOriginal: '/some/pathname' })
|
|
19
26
|
// ```
|
|
20
27
|
return;
|
|
21
28
|
}
|
|
22
|
-
(0, utils_js_1.
|
|
29
|
+
const urlOriginalNormalized = (0, utils_js_1.removeUrlOrigin)(pageContextInit.urlOriginal).urlModified;
|
|
30
|
+
(0, utils_js_1.assert)(urlOriginalNormalized.startsWith('/'));
|
|
23
31
|
const graph = copy(globalObject.redirectGraph);
|
|
24
32
|
graph[urlRedirectTarget] ?? (graph[urlRedirectTarget] = new Set());
|
|
25
|
-
graph[urlRedirectTarget].add(
|
|
33
|
+
graph[urlRedirectTarget].add(urlOriginalNormalized);
|
|
26
34
|
validate(graph);
|
|
27
35
|
globalObject.redirectGraph = graph;
|
|
28
36
|
}
|
|
@@ -84,10 +84,8 @@ async function createHttpResponsePageContextJson(pageContextSerialized) {
|
|
|
84
84
|
const httpResponse = createHttpResponse(200, 'application/json', [], pageContextSerialized, [], null);
|
|
85
85
|
return httpResponse;
|
|
86
86
|
}
|
|
87
|
-
function createHttpResponseRedirect({ url, statusCode },
|
|
88
|
-
|
|
89
|
-
urlLogical) {
|
|
90
|
-
(0, assertNoInfiniteHttpRedirect_js_1.assertNoInfiniteHttpRedirect)(url, urlLogical);
|
|
87
|
+
function createHttpResponseRedirect({ url, statusCode }, pageContextInit) {
|
|
88
|
+
(0, assertNoInfiniteHttpRedirect_js_1.assertNoInfiniteHttpRedirect)(url, pageContextInit);
|
|
91
89
|
(0, utils_js_1.assert)(url);
|
|
92
90
|
(0, utils_js_1.assert)(statusCode);
|
|
93
91
|
(0, utils_js_1.assert)(300 <= statusCode && statusCode <= 399);
|
|
@@ -346,7 +346,7 @@ async function normalizeUrl(pageContextInit, globalContext, httpRequestId) {
|
|
|
346
346
|
if (!urlNormalized)
|
|
347
347
|
return null;
|
|
348
348
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`URL normalized from ${picocolors_1.default.cyan(urlOriginal)} to ${picocolors_1.default.cyan(urlNormalized)} (https://vike.dev/url-normalization)`, httpRequestId, 'info');
|
|
349
|
-
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseRedirect)({ url: urlNormalized, statusCode: 301 }, pageContextInit
|
|
349
|
+
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseRedirect)({ url: urlNormalized, statusCode: 301 }, pageContextInit);
|
|
350
350
|
const pageContextHttpResponse = createPageContext(pageContextInit);
|
|
351
351
|
(0, utils_js_1.objectAssign)(pageContextHttpResponse, { httpResponse });
|
|
352
352
|
return pageContextHttpResponse;
|
|
@@ -388,7 +388,7 @@ async function getPermanentRedirect(pageContextInit, globalContext, httpRequestI
|
|
|
388
388
|
(0, utils_js_1.assert)(urlTarget !== pageContextInit.urlOriginal);
|
|
389
389
|
}
|
|
390
390
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`Permanent redirection defined by config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
|
|
391
|
-
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseRedirect)({ url: urlTarget, statusCode: 301 },
|
|
391
|
+
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseRedirect)({ url: urlTarget, statusCode: 301 }, pageContextInit);
|
|
392
392
|
const pageContextHttpResponse = createPageContext(pageContextInit);
|
|
393
393
|
(0, utils_js_1.objectAssign)(pageContextHttpResponse, { httpResponse });
|
|
394
394
|
return pageContextHttpResponse;
|
|
@@ -396,7 +396,9 @@ async function getPermanentRedirect(pageContextInit, globalContext, httpRequestI
|
|
|
396
396
|
function normalize(url) {
|
|
397
397
|
return url || '/';
|
|
398
398
|
}
|
|
399
|
-
async function handleAbortError(errAbort, pageContextsFromRewrite,
|
|
399
|
+
async function handleAbortError(errAbort, pageContextsFromRewrite,
|
|
400
|
+
// The original `pageContextInit` object passed to `renderPage(pageContextInit)`
|
|
401
|
+
pageContextInit,
|
|
400
402
|
// handleAbortError() creates a new pageContext object and we don't merge pageContextNominalPageInit to it: we only use some pageContextNominalPageInit information.
|
|
401
403
|
pageContextNominalPageInit, httpRequestId, pageContextErrorPageInit, globalContext) {
|
|
402
404
|
(0, abort_js_1.logAbortErrorHandled)(errAbort, globalContext.isProduction, pageContextNominalPageInit);
|
|
@@ -434,13 +436,7 @@ pageContextNominalPageInit, httpRequestId, pageContextErrorPageInit, globalConte
|
|
|
434
436
|
if (pageContextAbort._urlRedirect) {
|
|
435
437
|
const pageContextReturn = createPageContext(pageContextInit);
|
|
436
438
|
(0, utils_js_1.objectAssign)(pageContextReturn, pageContextAbort);
|
|
437
|
-
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseRedirect)(pageContextAbort._urlRedirect,
|
|
438
|
-
const { pathname, searchOriginal } = pageContextNominalPageInit.urlParsed;
|
|
439
|
-
const urlLogical = (0, utils_js_1.createUrlFromComponents)(null, pathname, searchOriginal,
|
|
440
|
-
// The server-side doesn't have access to the hash
|
|
441
|
-
null);
|
|
442
|
-
return urlLogical;
|
|
443
|
-
})());
|
|
439
|
+
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseRedirect)(pageContextAbort._urlRedirect, pageContextInit);
|
|
444
440
|
(0, utils_js_1.objectAssign)(pageContextReturn, { httpResponse });
|
|
445
441
|
return { pageContextReturn };
|
|
446
442
|
}
|
|
@@ -94,6 +94,7 @@ function modifyUrlPathname(url, modifier) {
|
|
|
94
94
|
function removeUrlOrigin(url) {
|
|
95
95
|
const { origin, pathnameOriginal, searchOriginal, hashOriginal } = (0, parseUrl_js_1.parseUrl)(url, '/');
|
|
96
96
|
const urlModified = (0, parseUrl_js_1.createUrlFromComponents)(null, pathnameOriginal, searchOriginal, hashOriginal);
|
|
97
|
+
(0, assert_js_1.assert)(urlModified.startsWith('/'));
|
|
97
98
|
return { urlModified, origin };
|
|
98
99
|
}
|
|
99
100
|
function setUrlOrigin(url, origin) {
|
|
@@ -1,23 +1,31 @@
|
|
|
1
1
|
export { assertNoInfiniteHttpRedirect };
|
|
2
|
-
import { assert, assertUsage, getGlobalObject } from '../../utils.js';
|
|
2
|
+
import { assert, assertUsage, getGlobalObject, removeUrlOrigin } from '../../utils.js';
|
|
3
3
|
import pc from '@brillout/picocolors';
|
|
4
4
|
const globalObject = getGlobalObject('createHttpResponse/assertNoInfiniteHttpRedirect.ts', {
|
|
5
5
|
redirectGraph: {}
|
|
6
6
|
});
|
|
7
|
-
|
|
7
|
+
// It's too strict, see https://github.com/vikejs/vike/issues/1270#issuecomment-1820608999
|
|
8
|
+
// - Let's create a new setting `+doNotCatchInfiniteRedirect` if someone complains.
|
|
9
|
+
function assertNoInfiniteHttpRedirect(
|
|
10
|
+
// The exact URL that the user will be redirected to.
|
|
11
|
+
// - It includes the Base URL as well as the locale (i18n) base.
|
|
12
|
+
urlRedirectTarget,
|
|
13
|
+
// Rationale for checking against `pageContextInit.urlOriginal`: https://github.com/vikejs/vike/pull/2264#issuecomment-2713890263
|
|
14
|
+
pageContextInit) {
|
|
8
15
|
if (!urlRedirectTarget.startsWith('/')) {
|
|
9
|
-
// 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).
|
|
10
|
-
// - There isn't a reliable way to check whether the redirect points to an external origin or the same origin
|
|
16
|
+
// 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 (at least not in itself).
|
|
17
|
+
// - There isn't a reliable way to check whether the redirect points to an external origin or the same origin; we hope/assume the user sets the URL without origin.
|
|
11
18
|
// ```js
|
|
12
19
|
// // For same-origin, the user usually/hopefully passes a URL without origin
|
|
13
20
|
// renderPage({ urlOriginal: '/some/pathname' })
|
|
14
21
|
// ```
|
|
15
22
|
return;
|
|
16
23
|
}
|
|
17
|
-
|
|
24
|
+
const urlOriginalNormalized = removeUrlOrigin(pageContextInit.urlOriginal).urlModified;
|
|
25
|
+
assert(urlOriginalNormalized.startsWith('/'));
|
|
18
26
|
const graph = copy(globalObject.redirectGraph);
|
|
19
27
|
graph[urlRedirectTarget] ?? (graph[urlRedirectTarget] = new Set());
|
|
20
|
-
graph[urlRedirectTarget].add(
|
|
28
|
+
graph[urlRedirectTarget].add(urlOriginalNormalized);
|
|
21
29
|
validate(graph);
|
|
22
30
|
globalObject.redirectGraph = graph;
|
|
23
31
|
}
|
|
@@ -35,4 +35,6 @@ declare function createHttpResponseError(pageContext: null | {
|
|
|
35
35
|
_pageConfigs: PageConfigRuntime[];
|
|
36
36
|
}): HttpResponse;
|
|
37
37
|
declare function createHttpResponsePageContextJson(pageContextSerialized: string): Promise<HttpResponse>;
|
|
38
|
-
declare function createHttpResponseRedirect({ url, statusCode }: UrlRedirect,
|
|
38
|
+
declare function createHttpResponseRedirect({ url, statusCode }: UrlRedirect, pageContextInit: {
|
|
39
|
+
urlOriginal: string;
|
|
40
|
+
}): HttpResponse;
|
|
@@ -82,10 +82,8 @@ async function createHttpResponsePageContextJson(pageContextSerialized) {
|
|
|
82
82
|
const httpResponse = createHttpResponse(200, 'application/json', [], pageContextSerialized, [], null);
|
|
83
83
|
return httpResponse;
|
|
84
84
|
}
|
|
85
|
-
function createHttpResponseRedirect({ url, statusCode },
|
|
86
|
-
|
|
87
|
-
urlLogical) {
|
|
88
|
-
assertNoInfiniteHttpRedirect(url, urlLogical);
|
|
85
|
+
function createHttpResponseRedirect({ url, statusCode }, pageContextInit) {
|
|
86
|
+
assertNoInfiniteHttpRedirect(url, pageContextInit);
|
|
89
87
|
assert(url);
|
|
90
88
|
assert(statusCode);
|
|
91
89
|
assert(300 <= statusCode && statusCode <= 399);
|
|
@@ -2,7 +2,7 @@ export { renderPage };
|
|
|
2
2
|
export { renderPage_addAsyncHookwrapper };
|
|
3
3
|
import { getPageContextInitEnhanced, renderPageAlreadyRouted } from './renderPage/renderPageAlreadyRouted.js';
|
|
4
4
|
import { route } from '../../shared/route/index.js';
|
|
5
|
-
import { assert, hasProp, objectAssign, isUrl, parseUrl, onSetupRuntime, assertWarning, getGlobalObject, checkType, assertUsage, normalizeUrlPathname, removeBaseServer, modifyUrlPathname, prependBase, removeUrlOrigin, setUrlOrigin,
|
|
5
|
+
import { assert, hasProp, objectAssign, isUrl, parseUrl, onSetupRuntime, assertWarning, getGlobalObject, checkType, assertUsage, normalizeUrlPathname, removeBaseServer, modifyUrlPathname, prependBase, removeUrlOrigin, setUrlOrigin, isUri, getUrlPretty } from './utils.js';
|
|
6
6
|
import { assertNoInfiniteAbortLoop, getPageContextFromAllRewrites, isAbortError, logAbortErrorHandled } from '../../shared/route/abort.js';
|
|
7
7
|
import { getGlobalContextInternal, initGlobalContext_renderPage } from './globalContext.js';
|
|
8
8
|
import { handlePageContextRequestUrl } from './renderPage/handlePageContextRequestUrl.js';
|
|
@@ -341,7 +341,7 @@ async function normalizeUrl(pageContextInit, globalContext, httpRequestId) {
|
|
|
341
341
|
if (!urlNormalized)
|
|
342
342
|
return null;
|
|
343
343
|
logRuntimeInfo?.(`URL normalized from ${pc.cyan(urlOriginal)} to ${pc.cyan(urlNormalized)} (https://vike.dev/url-normalization)`, httpRequestId, 'info');
|
|
344
|
-
const httpResponse = createHttpResponseRedirect({ url: urlNormalized, statusCode: 301 }, pageContextInit
|
|
344
|
+
const httpResponse = createHttpResponseRedirect({ url: urlNormalized, statusCode: 301 }, pageContextInit);
|
|
345
345
|
const pageContextHttpResponse = createPageContext(pageContextInit);
|
|
346
346
|
objectAssign(pageContextHttpResponse, { httpResponse });
|
|
347
347
|
return pageContextHttpResponse;
|
|
@@ -383,7 +383,7 @@ async function getPermanentRedirect(pageContextInit, globalContext, httpRequestI
|
|
|
383
383
|
assert(urlTarget !== pageContextInit.urlOriginal);
|
|
384
384
|
}
|
|
385
385
|
logRuntimeInfo?.(`Permanent redirection defined by config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
|
|
386
|
-
const httpResponse = createHttpResponseRedirect({ url: urlTarget, statusCode: 301 },
|
|
386
|
+
const httpResponse = createHttpResponseRedirect({ url: urlTarget, statusCode: 301 }, pageContextInit);
|
|
387
387
|
const pageContextHttpResponse = createPageContext(pageContextInit);
|
|
388
388
|
objectAssign(pageContextHttpResponse, { httpResponse });
|
|
389
389
|
return pageContextHttpResponse;
|
|
@@ -391,7 +391,9 @@ async function getPermanentRedirect(pageContextInit, globalContext, httpRequestI
|
|
|
391
391
|
function normalize(url) {
|
|
392
392
|
return url || '/';
|
|
393
393
|
}
|
|
394
|
-
async function handleAbortError(errAbort, pageContextsFromRewrite,
|
|
394
|
+
async function handleAbortError(errAbort, pageContextsFromRewrite,
|
|
395
|
+
// The original `pageContextInit` object passed to `renderPage(pageContextInit)`
|
|
396
|
+
pageContextInit,
|
|
395
397
|
// handleAbortError() creates a new pageContext object and we don't merge pageContextNominalPageInit to it: we only use some pageContextNominalPageInit information.
|
|
396
398
|
pageContextNominalPageInit, httpRequestId, pageContextErrorPageInit, globalContext) {
|
|
397
399
|
logAbortErrorHandled(errAbort, globalContext.isProduction, pageContextNominalPageInit);
|
|
@@ -429,13 +431,7 @@ pageContextNominalPageInit, httpRequestId, pageContextErrorPageInit, globalConte
|
|
|
429
431
|
if (pageContextAbort._urlRedirect) {
|
|
430
432
|
const pageContextReturn = createPageContext(pageContextInit);
|
|
431
433
|
objectAssign(pageContextReturn, pageContextAbort);
|
|
432
|
-
const httpResponse = createHttpResponseRedirect(pageContextAbort._urlRedirect,
|
|
433
|
-
const { pathname, searchOriginal } = pageContextNominalPageInit.urlParsed;
|
|
434
|
-
const urlLogical = createUrlFromComponents(null, pathname, searchOriginal,
|
|
435
|
-
// The server-side doesn't have access to the hash
|
|
436
|
-
null);
|
|
437
|
-
return urlLogical;
|
|
438
|
-
})());
|
|
434
|
+
const httpResponse = createHttpResponseRedirect(pageContextAbort._urlRedirect, pageContextInit);
|
|
439
435
|
objectAssign(pageContextReturn, { httpResponse });
|
|
440
436
|
return { pageContextReturn };
|
|
441
437
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.224-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.224-commit-00ed9fe";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.224-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.224-commit-00ed9fe';
|
|
@@ -92,6 +92,7 @@ function modifyUrlPathname(url, modifier) {
|
|
|
92
92
|
function removeUrlOrigin(url) {
|
|
93
93
|
const { origin, pathnameOriginal, searchOriginal, hashOriginal } = parseUrl(url, '/');
|
|
94
94
|
const urlModified = createUrlFromComponents(null, pathnameOriginal, searchOriginal, hashOriginal);
|
|
95
|
+
assert(urlModified.startsWith('/'));
|
|
95
96
|
return { urlModified, origin };
|
|
96
97
|
}
|
|
97
98
|
function setUrlOrigin(url, origin) {
|