vike 0.4.180 → 0.4.181-commit-ee50efa
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/envVars.js +7 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +3 -0
- package/dist/cjs/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.js +1 -2
- package/dist/cjs/{shared/route → node/runtime/renderPage}/resolveRedirects.js +9 -11
- package/dist/cjs/node/runtime/renderPage.js +6 -9
- package/dist/cjs/shared/getPageContextUrlComputed.js +43 -37
- package/dist/cjs/shared/modifyUrl.js +31 -0
- package/dist/cjs/shared/route/abort.js +4 -10
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +3 -1
- package/dist/cjs/utils/parseUrl.js +168 -87
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/redirectHard.js +7 -0
- package/dist/cjs/utils/urlToFile.js +1 -1
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +2 -2
- package/dist/esm/client/client-routing-runtime/navigate.js +2 -1
- package/dist/esm/client/client-routing-runtime/prefetch.js +5 -4
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +23 -21
- package/dist/esm/client/client-routing-runtime/skipLink.js +11 -22
- package/dist/esm/client/client-routing-runtime/utils.d.ts +1 -2
- package/dist/esm/client/client-routing-runtime/utils.js +1 -2
- package/dist/esm/node/plugin/plugins/envVars.d.ts +0 -2
- package/dist/esm/node/plugin/plugins/envVars.js +6 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +3 -0
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.js +2 -3
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +5 -5
- package/dist/esm/{shared/route → node/runtime/renderPage}/resolveRedirects.js +9 -11
- package/dist/esm/node/runtime/renderPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage.js +7 -10
- package/dist/esm/shared/getPageContextUrlComputed.d.ts +2 -24
- package/dist/esm/shared/getPageContextUrlComputed.js +43 -37
- package/dist/esm/shared/modifyUrl.d.ts +14 -0
- package/dist/esm/shared/modifyUrl.js +28 -0
- package/dist/esm/shared/route/abort.js +5 -11
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +4 -2
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/utils/parseUrl.d.ts +43 -10
- package/dist/esm/utils/parseUrl.js +167 -86
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/redirectHard.d.ts +1 -0
- package/dist/esm/utils/redirectHard.js +3 -0
- package/dist/esm/utils/urlToFile.js +1 -1
- package/package.json +17 -2
- package/dist/cjs/utils/isExternalLink.js +0 -7
- package/dist/cjs/utils/serverSideRouteTo.js +0 -7
- package/dist/esm/utils/isExternalLink.d.ts +0 -2
- package/dist/esm/utils/isExternalLink.js +0 -4
- package/dist/esm/utils/serverSideRouteTo.d.ts +0 -2
- package/dist/esm/utils/serverSideRouteTo.js +0 -4
- /package/dist/esm/{shared/route → node/runtime/renderPage}/resolveRedirects.d.ts +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.envVarsPlugin = void 0;
|
|
4
4
|
const vite_1 = require("vite");
|
|
5
5
|
const utils_js_1 = require("../utils.js");
|
|
6
6
|
const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
|
|
@@ -43,12 +43,13 @@ function envVarsPlugin() {
|
|
|
43
43
|
return !envPrefix.some((prefix) => key.startsWith(prefix));
|
|
44
44
|
})
|
|
45
45
|
.forEach(([envName, envVal]) => {
|
|
46
|
+
const envStatement = `import.meta.env.${envName}`;
|
|
47
|
+
const envStatementRegEx = new RegExp((0, utils_js_1.escapeRegex)(envStatement) + '\\b', 'g');
|
|
46
48
|
// Security check
|
|
47
49
|
{
|
|
48
|
-
const envStatement = getEnvStatement(envName);
|
|
49
50
|
const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !PUBLIC_ENV_WHITELIST.includes(envName);
|
|
50
51
|
if (isPrivate && isClientSide) {
|
|
51
|
-
if (!
|
|
52
|
+
if (!envStatementRegEx.test(code))
|
|
52
53
|
return;
|
|
53
54
|
const modulePath = (0, getFilePath_js_1.getModuleFilePath)(id, config);
|
|
54
55
|
const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
|
|
@@ -67,7 +68,7 @@ function envVarsPlugin() {
|
|
|
67
68
|
(0, utils_js_1.assert)(!(isPrivate && isClientSide) || !isBuild);
|
|
68
69
|
}
|
|
69
70
|
// Apply
|
|
70
|
-
code = applyEnvVar(
|
|
71
|
+
code = applyEnvVar(envStatementRegEx, envVal, code);
|
|
71
72
|
});
|
|
72
73
|
// Line numbers didn't change.
|
|
73
74
|
// - We only break the column number of a couple of lines, wich is acceptable.
|
|
@@ -78,14 +79,8 @@ function envVarsPlugin() {
|
|
|
78
79
|
};
|
|
79
80
|
}
|
|
80
81
|
exports.envVarsPlugin = envVarsPlugin;
|
|
81
|
-
function applyEnvVar(
|
|
82
|
-
|
|
83
|
-
const regex = new RegExp((0, utils_js_1.escapeRegex)(envStatement) + '\\b', 'g');
|
|
84
|
-
return code.replace(regex, JSON.stringify(envVal));
|
|
85
|
-
}
|
|
86
|
-
exports.applyEnvVar = applyEnvVar;
|
|
87
|
-
function getEnvStatement(envName) {
|
|
88
|
-
return `import.meta.env.${envName}`;
|
|
82
|
+
function applyEnvVar(envStatementRegEx, envVal, code) {
|
|
83
|
+
return code.replace(envStatementRegEx, JSON.stringify(envVal));
|
|
89
84
|
}
|
|
90
85
|
function getIsClientSide(config, options) {
|
|
91
86
|
const isBuild = config.command === 'build';
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -159,6 +159,9 @@ async function fastGlob(userRootDir, outDirRelativeFromUserRootDir) {
|
|
|
159
159
|
cwd: userRootDir,
|
|
160
160
|
dot: false
|
|
161
161
|
});
|
|
162
|
+
// Make build deterministic, in order to get a stable generated hash for dist/client/assets/entries/entry-client-routing.${hash}.js
|
|
163
|
+
// https://github.com/vikejs/vike/pull/1750
|
|
164
|
+
files.sort();
|
|
162
165
|
return files;
|
|
163
166
|
}
|
|
164
167
|
// Same as getIgnoreAsFilterFn() but as glob pattern
|
package/dist/cjs/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.js
CHANGED
|
@@ -10,7 +10,7 @@ const globalObject = (0, utils_js_1.getGlobalObject)('assertNoInfiniteHttpRedire
|
|
|
10
10
|
redirectGraph: {}
|
|
11
11
|
});
|
|
12
12
|
function assertNoInfiniteHttpRedirect(urlRedirectTarget, urlLogical) {
|
|
13
|
-
if (
|
|
13
|
+
if (!urlRedirectTarget.startsWith('/')) {
|
|
14
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
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
|
|
@@ -19,7 +19,6 @@ function assertNoInfiniteHttpRedirect(urlRedirectTarget, urlLogical) {
|
|
|
19
19
|
// ```
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
(0, utils_js_1.assert)(urlRedirectTarget.startsWith('/'));
|
|
23
22
|
(0, utils_js_1.assert)(urlLogical.startsWith('/'));
|
|
24
23
|
const graph = copy(globalObject.redirectGraph);
|
|
25
24
|
graph[urlRedirectTarget] ?? (graph[urlRedirectTarget] = new Set());
|
|
@@ -4,13 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.resolveRouteStringRedirect = exports.resolveRedirects = void 0;
|
|
7
|
-
const assertIsNotBrowser_js_1 = require("
|
|
8
|
-
const utils_js_1 = require("
|
|
9
|
-
const resolveUrlPathname_js_1 = require("
|
|
10
|
-
const resolveRouteString_js_1 = require("
|
|
7
|
+
const assertIsNotBrowser_js_1 = require("../../../utils/assertIsNotBrowser.js");
|
|
8
|
+
const utils_js_1 = require("../../../shared/utils.js");
|
|
9
|
+
const resolveUrlPathname_js_1 = require("../../../shared/route/resolveUrlPathname.js");
|
|
10
|
+
const resolveRouteString_js_1 = require("../../../shared/route/resolveRouteString.js");
|
|
11
11
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
12
12
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)(); // Don't bloat the client
|
|
13
|
-
// TODO/
|
|
13
|
+
// TODO/next-major-release: update
|
|
14
14
|
const configSrc = '[vite.config.js > vike({ redirects })]';
|
|
15
15
|
function resolveRedirects(redirects, urlPathname) {
|
|
16
16
|
for (const [urlSource, urlTarget] of Object.entries(redirects)) {
|
|
@@ -23,10 +23,8 @@ function resolveRedirects(redirects, urlPathname) {
|
|
|
23
23
|
exports.resolveRedirects = resolveRedirects;
|
|
24
24
|
function resolveRouteStringRedirect(urlSource, urlTarget, urlPathname) {
|
|
25
25
|
(0, resolveRouteString_js_1.assertRouteString)(urlSource, `${configSrc} Invalid`);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
(0, utils_js_1.isUriWithProtocol)(urlTarget) ||
|
|
29
|
-
urlTarget === '*', `${configSrc} Invalid redirection target URL ${picocolors_1.default.cyan(urlTarget)}: the target URL should start with ${picocolors_1.default.cyan('/')}, a valid protocol (${picocolors_1.default.cyan('https:')}, ${picocolors_1.default.cyan('http:')}, ${picocolors_1.default.cyan('mailto:')}, ${picocolors_1.default.cyan('ipfs:')}, ${picocolors_1.default.cyan('magnet:')}, ...), or be ${picocolors_1.default.cyan('*')}`);
|
|
26
|
+
// Is allowing any protocol a safety issue? https://github.com/vikejs/vike/pull/1292#issuecomment-1828043917
|
|
27
|
+
(0, utils_js_1.assertUsageUrlRedirectTarget)(urlTarget, `${configSrc} The URL redirection target`, true);
|
|
30
28
|
assertParams(urlSource, urlTarget);
|
|
31
29
|
const match = (0, resolveRouteString_js_1.resolveRouteString)(urlSource, urlPathname);
|
|
32
30
|
if (!match)
|
|
@@ -34,7 +32,7 @@ function resolveRouteStringRedirect(urlSource, urlTarget, urlPathname) {
|
|
|
34
32
|
const urlResolved = (0, resolveUrlPathname_js_1.resolveUrlPathname)(urlTarget, match.routeParams);
|
|
35
33
|
if (urlResolved === urlPathname)
|
|
36
34
|
return null;
|
|
37
|
-
(0, utils_js_1.assert)(
|
|
35
|
+
(0, utils_js_1.assert)((0, utils_js_1.isUrlRedirectTarget)(urlResolved));
|
|
38
36
|
return urlResolved;
|
|
39
37
|
}
|
|
40
38
|
exports.resolveRouteStringRedirect = resolveRouteStringRedirect;
|
|
@@ -43,7 +41,7 @@ function assertParams(urlSource, urlTarget) {
|
|
|
43
41
|
routeSegments.forEach((routeSegment) => {
|
|
44
42
|
if (routeSegment.startsWith('@') || routeSegment.startsWith('*')) {
|
|
45
43
|
const segments = urlSource.split('/');
|
|
46
|
-
(0, utils_js_1.assertUsage)(segments.includes(routeSegment), `${configSrc} The redirection source URL ${picocolors_1.default.
|
|
44
|
+
(0, utils_js_1.assertUsage)(segments.includes(routeSegment), `${configSrc} The redirection source URL ${picocolors_1.default.string(urlSource)} is missing the URL parameter ${picocolors_1.default.string(routeSegment)} used by the redirection target URL ${picocolors_1.default.string(urlTarget)}`);
|
|
47
45
|
}
|
|
48
46
|
});
|
|
49
47
|
}
|
|
@@ -21,7 +21,7 @@ const serializePageContextClientSide_js_1 = require("./html/serializePageContext
|
|
|
21
21
|
const error_page_js_1 = require("../../shared/error-page.js");
|
|
22
22
|
const handleErrorWithoutErrorPage_js_1 = require("./renderPage/handleErrorWithoutErrorPage.js");
|
|
23
23
|
const loadUserFilesServerSide_js_1 = require("./renderPage/loadUserFilesServerSide.js");
|
|
24
|
-
const resolveRedirects_js_1 = require("
|
|
24
|
+
const resolveRedirects_js_1 = require("./renderPage/resolveRedirects.js");
|
|
25
25
|
const globalObject = (0, utils_js_1.getGlobalObject)('runtime/renderPage.ts', {
|
|
26
26
|
httpRequestsCount: 0,
|
|
27
27
|
pendingRequestsCount: 0
|
|
@@ -332,12 +332,9 @@ function getRequestId() {
|
|
|
332
332
|
return httpRequestId;
|
|
333
333
|
}
|
|
334
334
|
function isIgnoredUrl(urlOriginal) {
|
|
335
|
-
const
|
|
336
|
-
(0, utils_js_1.assertWarning)(!
|
|
337
|
-
return (urlOriginal.endsWith('/__vite_ping') ||
|
|
338
|
-
urlOriginal.endsWith('/favicon.ico') ||
|
|
339
|
-
!(0, utils_js_1.isParsable)(urlOriginal) ||
|
|
340
|
-
isViteClientRequest);
|
|
335
|
+
const isViteRequest = urlOriginal.endsWith('/@vite/client') || urlOriginal.startsWith('/@fs/');
|
|
336
|
+
(0, utils_js_1.assertWarning)(!isViteRequest, `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 });
|
|
337
|
+
return (urlOriginal.endsWith('/__vite_ping') || urlOriginal.endsWith('/favicon.ico') || !(0, utils_js_1.isUrl)(urlOriginal) || isViteRequest);
|
|
341
338
|
}
|
|
342
339
|
function normalizeUrl(pageContextInit, httpRequestId) {
|
|
343
340
|
const { trailingSlash, disableUrlNormalization, baseServer } = (0, globalContext_js_1.getGlobalContext)();
|
|
@@ -365,9 +362,9 @@ function getPermanentRedirect(pageContextInit, httpRequestId) {
|
|
|
365
362
|
const urlTarget = (0, resolveRedirects_js_1.resolveRedirects)(redirects, urlPathname);
|
|
366
363
|
if (urlTarget === null)
|
|
367
364
|
return null;
|
|
368
|
-
if (!(0, utils_js_1.
|
|
365
|
+
if (!(0, utils_js_1.isUrl)(urlTarget)) {
|
|
369
366
|
// E.g. `urlTarget === 'mailto:some@example.com'`
|
|
370
|
-
(0, utils_js_1.assert)((0, utils_js_1.
|
|
367
|
+
(0, utils_js_1.assert)((0, utils_js_1.isUri)(urlTarget));
|
|
371
368
|
urlTargetExternal = urlTarget;
|
|
372
369
|
return null;
|
|
373
370
|
}
|
|
@@ -30,11 +30,6 @@ function getPageContextUrlComputed(pageContext) {
|
|
|
30
30
|
}
|
|
31
31
|
exports.getPageContextUrlComputed = getPageContextUrlComputed;
|
|
32
32
|
function getUrlParsed(pageContext) {
|
|
33
|
-
// We need a url handler function because the onBeforeRoute() hook may set pageContext.urlLogical (typically for i18n)
|
|
34
|
-
let urlHandler = pageContext._urlHandler;
|
|
35
|
-
if (!urlHandler) {
|
|
36
|
-
urlHandler = (url) => url;
|
|
37
|
-
}
|
|
38
33
|
// Example of i18n app using `throw render()`:
|
|
39
34
|
// 1. User goes to '/fr-FR/admin'.
|
|
40
35
|
// 2. The first onBeforeRoute() call accesses pageContext.urlPathname (its value is '/fr-FR/admin': the pathname of pageContext.urlOriginal, since both pageContext.urlLogical and pageContext._urlRewrite are undefined) and sets pageContext.urlLogical to '/admin'.
|
|
@@ -43,23 +38,36 @@ function getUrlParsed(pageContext) {
|
|
|
43
38
|
// 5. The second onBeforeRoute() call accesses pageContext.urlPathname (its value is '/fr-FR/login': the pathname of pageContext._urlRewrite, since pageContext.urlLogical is undefined) and sets pageContext.urlLogical to '/login'.
|
|
44
39
|
// 6. The value of pageContext.urlPathname is now '/login': the pathname of `pageContext.urlLogical`. (While pageContext.urlOriginal is still '/fr-FR/admin'.)
|
|
45
40
|
// Reproduction: https://github.com/vikejs/vike/discussions/1436#discussioncomment-8142023
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
// Determine logical URL
|
|
42
|
+
let urlResolved;
|
|
43
|
+
let baseToBeRemoved;
|
|
44
|
+
if (pageContext.urlLogical) {
|
|
45
|
+
// Set by onBeforeRoute()
|
|
46
|
+
urlResolved = pageContext.urlLogical;
|
|
47
|
+
baseToBeRemoved = false;
|
|
48
|
+
}
|
|
49
|
+
else if (pageContext._urlRewrite) {
|
|
49
50
|
// Set by `throw render()`
|
|
50
|
-
pageContext._urlRewrite
|
|
51
|
+
urlResolved = pageContext._urlRewrite;
|
|
52
|
+
baseToBeRemoved = false;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
51
55
|
// Set by renderPage()
|
|
52
|
-
pageContext.urlOriginal;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
console.log('pageContext.urlLogical', pageContext.urlLogical)
|
|
56
|
-
console.log('pageContext._urlRewrite', pageContext._urlRewrite)
|
|
57
|
-
console.log('pageContext.urlOriginal', pageContext.urlOriginal)
|
|
58
|
-
console.log()
|
|
59
|
-
//*/
|
|
60
|
-
const baseServer = pageContext._baseServer;
|
|
56
|
+
urlResolved = pageContext.urlOriginal;
|
|
57
|
+
baseToBeRemoved = true;
|
|
58
|
+
}
|
|
61
59
|
(0, utils_js_1.assert)(urlResolved && typeof urlResolved === 'string');
|
|
62
|
-
|
|
60
|
+
// Remove .pageContext.json
|
|
61
|
+
let urlHandler = pageContext._urlHandler;
|
|
62
|
+
if (!urlHandler)
|
|
63
|
+
urlHandler = (url) => url;
|
|
64
|
+
urlResolved = urlHandler(urlResolved);
|
|
65
|
+
// Remove Base URL.
|
|
66
|
+
// - We assume there isn't any Base URL to the URLs set by the user at `throw render()` and onBeforeRoute()
|
|
67
|
+
// - This makes sense because the Base URL is merely a setting: ideally the user should write code that doesn't know anything about it (so that the user can remove/add/change Base URL without having to modify any code).
|
|
68
|
+
// - pageContext.urlOriginal is the URL of the HTTP request and thus contains the Base URL.
|
|
69
|
+
const baseServer = !baseToBeRemoved ? '/' : pageContext._baseServer;
|
|
70
|
+
// Parse URL
|
|
63
71
|
return (0, utils_js_1.parseUrl)(urlResolved, baseServer);
|
|
64
72
|
}
|
|
65
73
|
function urlPathnameGetter() {
|
|
@@ -74,47 +82,45 @@ function urlGetter() {
|
|
|
74
82
|
return urlPathnameGetter.call(this);
|
|
75
83
|
}
|
|
76
84
|
function urlParsedGetter() {
|
|
77
|
-
const
|
|
78
|
-
|
|
85
|
+
const {
|
|
86
|
+
// remove hasBaseServer as it isn't part of UrlPublic
|
|
87
|
+
hasBaseServer: _, ...urlParsed } = getUrlParsed(this);
|
|
79
88
|
const hashIsAvailable = (0, utils_js_1.isBrowser)();
|
|
80
89
|
const warnHashNotAvailable = (prop) => {
|
|
81
90
|
(0, utils_js_1.assertWarning)(hashIsAvailable, `pageContext.urlParsed.${prop} isn't available on the server-side (HTTP requests don't include the URL hash)`, { onlyOnce: true, showStackTrace: true });
|
|
82
91
|
};
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
pathname,
|
|
86
|
-
pathnameOriginal,
|
|
87
|
-
search,
|
|
88
|
-
searchAll,
|
|
89
|
-
searchOriginal,
|
|
92
|
+
const urlParsedEnhanced = {
|
|
93
|
+
...urlParsed,
|
|
90
94
|
get hash() {
|
|
91
95
|
warnHashNotAvailable('hash');
|
|
92
|
-
return hash;
|
|
96
|
+
return urlParsed.hash;
|
|
93
97
|
},
|
|
94
98
|
get hashOriginal() {
|
|
95
99
|
warnHashNotAvailable('hashOriginal');
|
|
96
|
-
return hashOriginal;
|
|
100
|
+
return urlParsed.hashOriginal;
|
|
97
101
|
},
|
|
102
|
+
// TODO/next-major-release: remove
|
|
98
103
|
get hashString() {
|
|
99
104
|
(0, utils_js_1.assertWarning)(false, 'pageContext.urlParsed.hashString has been renamed to pageContext.urlParsed.hashOriginal', {
|
|
100
105
|
onlyOnce: true,
|
|
101
106
|
showStackTrace: true
|
|
102
107
|
});
|
|
103
108
|
warnHashNotAvailable('hashString');
|
|
104
|
-
return hashOriginal;
|
|
109
|
+
return urlParsed.hashOriginal;
|
|
105
110
|
},
|
|
111
|
+
// TODO/next-major-release: remove
|
|
106
112
|
get searchString() {
|
|
107
113
|
(0, utils_js_1.assertWarning)(false, 'pageContext.urlParsed.searchString has been renamed to pageContext.urlParsed.searchOriginal', { onlyOnce: true, showStackTrace: true });
|
|
108
|
-
return searchOriginal;
|
|
114
|
+
return urlParsed.searchOriginal;
|
|
109
115
|
}
|
|
110
116
|
};
|
|
111
|
-
(0, utils_js_1.changeEnumerable)(
|
|
112
|
-
(0, utils_js_1.changeEnumerable)(
|
|
117
|
+
(0, utils_js_1.changeEnumerable)(urlParsedEnhanced, 'hashString', false);
|
|
118
|
+
(0, utils_js_1.changeEnumerable)(urlParsedEnhanced, 'searchString', false);
|
|
113
119
|
if (!hashIsAvailable) {
|
|
114
|
-
(0, utils_js_1.changeEnumerable)(
|
|
115
|
-
(0, utils_js_1.changeEnumerable)(
|
|
120
|
+
(0, utils_js_1.changeEnumerable)(urlParsedEnhanced, 'hash', false);
|
|
121
|
+
(0, utils_js_1.changeEnumerable)(urlParsedEnhanced, 'hashOriginal', false);
|
|
116
122
|
}
|
|
117
|
-
return
|
|
123
|
+
return urlParsedEnhanced;
|
|
118
124
|
}
|
|
119
125
|
function assertPageContextUrl(pageContext) {
|
|
120
126
|
(0, utils_js_1.assert)(typeof pageContext.urlOriginal === 'string');
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.modifyUrl = void 0;
|
|
4
|
+
const utils_js_1 = require("./utils.js");
|
|
5
|
+
/**
|
|
6
|
+
* Modify a URL.
|
|
7
|
+
*
|
|
8
|
+
* Example: changing the URL pathname for internationalization.
|
|
9
|
+
*
|
|
10
|
+
* https://vike.dev/modifyUrl
|
|
11
|
+
*/
|
|
12
|
+
function modifyUrl(url, modify) {
|
|
13
|
+
const urlParsed = (0, utils_js_1.parseUrl)(url, '/');
|
|
14
|
+
// Pathname
|
|
15
|
+
const pathname = modify.pathname ?? urlParsed.pathname;
|
|
16
|
+
// Origin
|
|
17
|
+
const originParts = [
|
|
18
|
+
modify.protocol ?? urlParsed.protocol ?? '',
|
|
19
|
+
modify.hostname ?? urlParsed.hostname ?? ''
|
|
20
|
+
];
|
|
21
|
+
const port = modify.port ?? urlParsed.port;
|
|
22
|
+
if (port || port === 0) {
|
|
23
|
+
originParts.push(`:${port}`);
|
|
24
|
+
}
|
|
25
|
+
const origin = originParts.join('');
|
|
26
|
+
const urlModified = (0, utils_js_1.createUrlFromComponents)(origin, pathname,
|
|
27
|
+
// Should we also support modifying search and hash?
|
|
28
|
+
urlParsed.searchOriginal, urlParsed.hashOriginal);
|
|
29
|
+
return urlModified;
|
|
30
|
+
}
|
|
31
|
+
exports.modifyUrl = modifyUrl;
|
|
@@ -17,7 +17,7 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
17
17
|
*/
|
|
18
18
|
function redirect(url, statusCode) {
|
|
19
19
|
const abortCaller = 'throw redirect()';
|
|
20
|
-
|
|
20
|
+
(0, utils_js_1.assertUsageUrlRedirectTarget)(url, getErrPrefix(abortCaller));
|
|
21
21
|
const args = [JSON.stringify(url)];
|
|
22
22
|
if (!statusCode) {
|
|
23
23
|
statusCode = 302;
|
|
@@ -59,7 +59,7 @@ function render_(urlOrStatusCode, abortReason, abortCall, abortCaller, pageConte
|
|
|
59
59
|
}
|
|
60
60
|
if (typeof urlOrStatusCode === 'string') {
|
|
61
61
|
const url = urlOrStatusCode;
|
|
62
|
-
|
|
62
|
+
(0, utils_js_1.assertUsageUrlPathnameAbsolute)(url, getErrPrefix(abortCaller));
|
|
63
63
|
(0, utils_js_1.objectAssign)(pageContextAbort, {
|
|
64
64
|
_urlRewrite: url
|
|
65
65
|
});
|
|
@@ -174,12 +174,6 @@ function assertNoInfiniteAbortLoop(rewriteCount, redirectCount) {
|
|
|
174
174
|
(0, utils_js_1.assertUsage)(rewriteCount + redirectCount <= 7, `Maximum chain length of 7 ${abortCalls} exceeded. Did you define an infinite loop of ${abortCalls}?`);
|
|
175
175
|
}
|
|
176
176
|
exports.assertNoInfiniteAbortLoop = assertNoInfiniteAbortLoop;
|
|
177
|
-
function
|
|
178
|
-
|
|
179
|
-
`Invalid URL ${picocolors_1.default.cyan(url)} passed to ${picocolors_1.default.cyan(abortCaller)}:`,
|
|
180
|
-
`the URL should start with ${picocolors_1.default.cyan('/')}`,
|
|
181
|
-
allowAbsoluteUrl && `or a valid protocol (${picocolors_1.default.cyan('https:')}, ${picocolors_1.default.cyan('ipfs:')}, ...)`
|
|
182
|
-
]
|
|
183
|
-
.filter(Boolean)
|
|
184
|
-
.join(' '));
|
|
177
|
+
function getErrPrefix(abortCaller) {
|
|
178
|
+
return `URL passed to ${picocolors_1.default.code(abortCaller)}`;
|
|
185
179
|
}
|
|
@@ -71,7 +71,9 @@ async function getPageContextFromHook(onBeforeRouteHook, pageContext) {
|
|
|
71
71
|
delete hookReturn.pageContext.urlOriginal;
|
|
72
72
|
}
|
|
73
73
|
if ((0, utils_js_1.hasProp)(hookReturn.pageContext, 'urlLogical')) {
|
|
74
|
-
(0, utils_js_1.
|
|
74
|
+
(0, utils_js_1.assertUsageUrlPathnameAbsolute)(
|
|
75
|
+
// We type-cast to string instead of assertUsage() in order to save client-side KBs
|
|
76
|
+
hookReturn.pageContext.urlLogical, `${errPrefix} returned ${picocolors_1.default.cyan('{ pageContext: { urlLogical } }')} but ${picocolors_1.default.cyan('urlLogical')}`);
|
|
75
77
|
}
|
|
76
78
|
(0, assertPageContextProvidedByUser_js_1.assertPageContextProvidedByUser)(hookReturn.pageContext, {
|
|
77
79
|
hookFilePath: onBeforeRouteHook.hookFilePath,
|