vike 0.4.222-commit-6647d1e → 0.4.222-commit-ce4e16e
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/buildApp.js +9 -5
- package/dist/cjs/node/plugin/plugins/buildConfig.js +3 -0
- package/dist/cjs/node/plugin/plugins/envVars.js +2 -18
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +2 -2
- package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +1 -1
- package/dist/cjs/node/plugin/shared/viteIsSSR.js +19 -10
- package/dist/cjs/node/runtime/globalContext.js +1 -1
- package/dist/cjs/node/runtime/renderPage.js +17 -13
- package/dist/cjs/node/runtime/universal-middleware.js +14 -0
- package/dist/cjs/shared/getPageContextUrlComputed.js +2 -2
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assert.js +1 -1
- package/dist/cjs/utils/parseUrl-extras.js +2 -2
- package/dist/cjs/utils/parseUrl.js +5 -5
- package/dist/esm/client/client-routing-runtime/skipLink.js +2 -2
- package/dist/esm/node/plugin/plugins/buildApp.js +9 -5
- package/dist/esm/node/plugin/plugins/buildConfig.js +3 -0
- package/dist/esm/node/plugin/plugins/envVars.js +2 -18
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +3 -3
- package/dist/esm/node/plugin/shared/getHttpRequestAsyncStore.js +2 -2
- package/dist/esm/node/plugin/shared/viteIsSSR.d.ts +7 -4
- package/dist/esm/node/plugin/shared/viteIsSSR.js +20 -11
- package/dist/esm/node/runtime/globalContext.js +1 -1
- package/dist/esm/node/runtime/renderPage.d.ts +5 -5
- package/dist/esm/node/runtime/renderPage.js +17 -12
- package/dist/esm/node/runtime/universal-middleware.d.ts +1 -0
- package/dist/esm/node/runtime/universal-middleware.js +11 -0
- package/dist/esm/shared/getPageContextUrlComputed.js +2 -2
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assert.js +1 -1
- package/dist/esm/utils/parseUrl-extras.js +2 -2
- package/dist/esm/utils/parseUrl.d.ts +3 -4
- package/dist/esm/utils/parseUrl.js +5 -5
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +15 -2
- package/universal-middleware.js +3 -0
|
@@ -9,6 +9,9 @@ const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js"
|
|
|
9
9
|
const getFullBuildInlineConfig_js_1 = require("../shared/getFullBuildInlineConfig.js");
|
|
10
10
|
function buildApp() {
|
|
11
11
|
let config;
|
|
12
|
+
// `builder.buildApp` can be overriden by another plugin e.g vike-vercel https://github.com/vikejs/vike/pull/2184#issuecomment-2659425195
|
|
13
|
+
// In that case, we should'nt `forceExit`.
|
|
14
|
+
let forceExit = false;
|
|
12
15
|
return [
|
|
13
16
|
{
|
|
14
17
|
name: 'vike:buildApp',
|
|
@@ -23,6 +26,10 @@ function buildApp() {
|
|
|
23
26
|
(0, utils_js_1.assert)(builder.environments.ssr);
|
|
24
27
|
await builder.build(builder.environments.client);
|
|
25
28
|
await builder.build(builder.environments.ssr);
|
|
29
|
+
if (forceExit) {
|
|
30
|
+
(0, runPrerender_js_1.runPrerender_forceExit)();
|
|
31
|
+
(0, utils_js_1.assert)(false);
|
|
32
|
+
}
|
|
26
33
|
}
|
|
27
34
|
},
|
|
28
35
|
environments: {
|
|
@@ -61,11 +68,8 @@ function buildApp() {
|
|
|
61
68
|
if (!(0, context_js_1.isPrerenderAutoRunEnabled)(vikeConfig))
|
|
62
69
|
return;
|
|
63
70
|
const configInline = (0, getFullBuildInlineConfig_js_1.getFullBuildInlineConfig)(config);
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
(0, runPrerender_js_1.runPrerender_forceExit)();
|
|
67
|
-
(0, utils_js_1.assert)(false);
|
|
68
|
-
}
|
|
71
|
+
const res = await (0, runPrerender_js_1.runPrerenderFromAutoRun)(configInline, config);
|
|
72
|
+
forceExit = res.forceExit;
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
75
|
];
|
|
@@ -86,6 +86,9 @@ function buildConfig() {
|
|
|
86
86
|
{
|
|
87
87
|
name: 'vike:buildConfig:pre',
|
|
88
88
|
apply: 'build',
|
|
89
|
+
applyToEnvironment(env) {
|
|
90
|
+
return env.name === 'ssr';
|
|
91
|
+
},
|
|
89
92
|
// Make sure other writeBundle() hooks are called after this writeBundle() hook.
|
|
90
93
|
// - set_ASSETS_MANIFEST() needs to be called before dist/server/ code is executed.
|
|
91
94
|
// - For example, the writeBundle() hook of vite-plugin-vercel needs to be called after this writeBundle() hook, otherwise: https://github.com/vikejs/vike/issues/1527
|
|
@@ -6,6 +6,7 @@ const utils_js_1 = require("../utils.js");
|
|
|
6
6
|
const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
|
|
7
7
|
const getFilePath_js_1 = require("../shared/getFilePath.js");
|
|
8
8
|
const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
9
|
+
const viteIsSSR_js_1 = require("../shared/viteIsSSR.js");
|
|
9
10
|
// TODO/enventually: (after we implemented vike.config.js)
|
|
10
11
|
// - Make import.meta.env work inside +config.js
|
|
11
12
|
// - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
|
|
@@ -38,7 +39,7 @@ function envVarsPlugin() {
|
|
|
38
39
|
if (!code.includes('import.meta.env.'))
|
|
39
40
|
return;
|
|
40
41
|
const isBuild = config.command === 'build';
|
|
41
|
-
const isClientSide =
|
|
42
|
+
const isClientSide = !(0, viteIsSSR_js_1.viteIsSSR_safe)(config, options);
|
|
42
43
|
Object.entries(envsAll)
|
|
43
44
|
.filter(([key]) => {
|
|
44
45
|
// Already handled by Vite
|
|
@@ -84,20 +85,3 @@ function envVarsPlugin() {
|
|
|
84
85
|
function applyEnvVar(envStatementRegEx, envVal, code) {
|
|
85
86
|
return code.replace(envStatementRegEx, JSON.stringify(envVal));
|
|
86
87
|
}
|
|
87
|
-
function getIsClientSide(config, options) {
|
|
88
|
-
const isBuild = config.command === 'build';
|
|
89
|
-
if (isBuild) {
|
|
90
|
-
(0, utils_js_1.assert)(typeof config.build.ssr === 'boolean');
|
|
91
|
-
const isServerSide = config.build.ssr;
|
|
92
|
-
if (options !== undefined) {
|
|
93
|
-
(0, utils_js_1.assert)(options.ssr === isServerSide);
|
|
94
|
-
}
|
|
95
|
-
return !isServerSide;
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
(0, utils_js_1.assert)(config.build.ssr === false);
|
|
99
|
-
(0, utils_js_1.assert)(typeof options?.ssr === 'boolean');
|
|
100
|
-
const isServerSide = options.ssr;
|
|
101
|
-
return !isServerSide;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
@@ -48,7 +48,7 @@ function extractAssetsPlugin() {
|
|
|
48
48
|
}
|
|
49
49
|
// TODO/now: add meta.default
|
|
50
50
|
(0, utils_js_1.assert)(vikeConfig.global.config.includeAssetsImportedByServer ?? true);
|
|
51
|
-
(0, utils_js_1.assert)(!(0, viteIsSSR_js_1.
|
|
51
|
+
(0, utils_js_1.assert)(!(0, viteIsSSR_js_1.viteIsSSR_safe)(config, options));
|
|
52
52
|
const importStatements = await (0, parseEsModule_js_1.getImportStatements)(src);
|
|
53
53
|
const moduleNames = getImportedModules(importStatements);
|
|
54
54
|
const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
|
|
@@ -65,7 +65,7 @@ function extractAssetsPlugin() {
|
|
|
65
65
|
// - Vite's `vite:resolve` plugin; https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
|
|
66
66
|
enforce: 'pre',
|
|
67
67
|
async resolveId(source, importer, options) {
|
|
68
|
-
if ((0, viteIsSSR_js_1.
|
|
68
|
+
if ((0, viteIsSSR_js_1.viteIsSSR_safe)(config, options)) {
|
|
69
69
|
// When building for the server, there should never be a `?extractAssets` query
|
|
70
70
|
(0, utils_js_1.assert)(!extractAssetsRE.test(source));
|
|
71
71
|
(0, utils_js_1.assert)(importer === undefined || !extractAssetsRE.test(importer));
|
|
@@ -55,7 +55,7 @@ async function installHttpRequestAsyncStore() {
|
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
asyncLocalStorage = new mod.AsyncLocalStorage();
|
|
58
|
-
(0, renderPage_js_1.
|
|
58
|
+
(0, renderPage_js_1.renderPage_addAsyncHookwrapper)(async (httpRequestId, renderPage) => {
|
|
59
59
|
(0, utils_js_1.assert)(asyncLocalStorage);
|
|
60
60
|
const loggedErrors = new Set();
|
|
61
61
|
const markErrorAsLogged = (err) => {
|
|
@@ -2,21 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.viteIsSSR = viteIsSSR;
|
|
4
4
|
exports.viteIsSSR_options = viteIsSSR_options;
|
|
5
|
+
exports.viteIsSSR_safe = viteIsSSR_safe;
|
|
5
6
|
const assert_js_1 = require("../../../utils/assert.js");
|
|
6
|
-
const isObject_js_1 = require("../../../utils/isObject.js");
|
|
7
7
|
function viteIsSSR(config) {
|
|
8
8
|
return !!config?.build?.ssr;
|
|
9
9
|
}
|
|
10
|
-
// https://github.com/vitejs/vite/discussions/5109#discussioncomment-1450726
|
|
11
10
|
function viteIsSSR_options(options) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
return !!options?.ssr;
|
|
12
|
+
}
|
|
13
|
+
// Vite is quite messy about setting `ssr: boolean`, thus we use an extra safe implemention for security purposes.
|
|
14
|
+
// It's used for .client.js and .server.js guarantee thus we use agressive assert() calls for added safety.
|
|
15
|
+
function viteIsSSR_safe(config, options) {
|
|
16
|
+
if (config.command === 'build') {
|
|
17
|
+
(0, assert_js_1.assert)(typeof config.build.ssr === 'boolean');
|
|
18
|
+
const val = config.build.ssr;
|
|
19
|
+
if (options?.ssr !== undefined)
|
|
20
|
+
(0, assert_js_1.assert)(val === options.ssr);
|
|
21
|
+
return val;
|
|
17
22
|
}
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
else {
|
|
24
|
+
(0, assert_js_1.assert)(typeof options?.ssr === 'boolean');
|
|
25
|
+
const val = options.ssr;
|
|
26
|
+
/* This assert() fails (which is very unexpected).
|
|
27
|
+
if (typeof config.build.ssr === 'boolean') assert(val === config.build.ssr)
|
|
28
|
+
//*/
|
|
29
|
+
return val;
|
|
20
30
|
}
|
|
21
|
-
(0, assert_js_1.assert)(false);
|
|
22
31
|
}
|
|
@@ -127,7 +127,7 @@ function getViteConfig() {
|
|
|
127
127
|
}
|
|
128
128
|
async function initGlobalContext_renderPage() {
|
|
129
129
|
debug('initGlobalContext_renderPage()');
|
|
130
|
-
// globalObject.isProduction
|
|
130
|
+
// `globalObject.isProduction === undefined` when using production server without `vike-server`. (There isn't any reliable signal we can use to determine early whether the environement is production or development.)
|
|
131
131
|
if (globalObject.isProduction === undefined)
|
|
132
132
|
setIsProduction(true);
|
|
133
133
|
await initGlobalContext();
|
|
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.renderPage_addWrapper = void 0;
|
|
7
6
|
exports.renderPage = renderPage;
|
|
7
|
+
exports.renderPage_addAsyncHookwrapper = renderPage_addAsyncHookwrapper;
|
|
8
8
|
const renderPageAlreadyRouted_js_1 = require("./renderPage/renderPageAlreadyRouted.js");
|
|
9
9
|
const index_js_1 = require("../../shared/route/index.js");
|
|
10
10
|
const utils_js_1 = require("./utils.js");
|
|
@@ -26,13 +26,6 @@ const resolveRedirects_js_1 = require("./renderPage/resolveRedirects.js");
|
|
|
26
26
|
const globalObject = (0, utils_js_1.getGlobalObject)('runtime/renderPage.ts', {
|
|
27
27
|
httpRequestsCount: 0
|
|
28
28
|
});
|
|
29
|
-
let renderPage_wrapper = async (_httpRequestId, ret) => ({
|
|
30
|
-
pageContextReturn: await ret()
|
|
31
|
-
});
|
|
32
|
-
const renderPage_addWrapper = (wrapper) => {
|
|
33
|
-
renderPage_wrapper = wrapper;
|
|
34
|
-
};
|
|
35
|
-
exports.renderPage_addWrapper = renderPage_addWrapper;
|
|
36
29
|
// `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.)
|
|
37
30
|
async function renderPage(pageContextInit) {
|
|
38
31
|
(0, assertArguments_js_1.assertArguments)(...arguments);
|
|
@@ -46,12 +39,20 @@ async function renderPage(pageContextInit) {
|
|
|
46
39
|
const httpRequestId = getRequestId();
|
|
47
40
|
const urlOriginalPretty = (0, utils_js_1.getUrlPretty)(pageContextInit.urlOriginal);
|
|
48
41
|
logHttpRequest(urlOriginalPretty, httpRequestId);
|
|
49
|
-
const { pageContextReturn } = await
|
|
42
|
+
const { pageContextReturn } = await asyncHookWrapper(httpRequestId, () => renderPageAndPrepare(pageContextInit, httpRequestId));
|
|
50
43
|
logHttpResponse(urlOriginalPretty, httpRequestId, pageContextReturn);
|
|
51
44
|
(0, utils_js_1.checkType)(pageContextReturn);
|
|
52
45
|
(0, utils_js_1.assert)(pageContextReturn.httpResponse);
|
|
53
46
|
return pageContextReturn;
|
|
54
47
|
}
|
|
48
|
+
// Fallback wrapper if node:async_hooks isn't available
|
|
49
|
+
let asyncHookWrapper = async (_httpRequestId, ret) => ({
|
|
50
|
+
pageContextReturn: await ret()
|
|
51
|
+
});
|
|
52
|
+
// Add node:async_hooks wrapper
|
|
53
|
+
function renderPage_addAsyncHookwrapper(wrapper) {
|
|
54
|
+
asyncHookWrapper = wrapper;
|
|
55
|
+
}
|
|
55
56
|
async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
56
57
|
// Invalid config
|
|
57
58
|
const handleInvalidConfig = (err) => {
|
|
@@ -70,8 +71,11 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
|
70
71
|
await (0, globalContext_js_1.initGlobalContext_renderPage)();
|
|
71
72
|
}
|
|
72
73
|
catch (err) {
|
|
73
|
-
// Errors are expected since assertUsage() is used in
|
|
74
|
-
//
|
|
74
|
+
// Errors are expected since assertUsage() is used in initGlobalContext_renderPage() such as:
|
|
75
|
+
// ```bash
|
|
76
|
+
// Re-build your app (you're using 1.2.3 but your app was built with 1.2.2)
|
|
77
|
+
// ```
|
|
78
|
+
// initGlobalContext_renderPage() doens't call any user hook => err isn't thrown from user code.
|
|
75
79
|
(0, utils_js_1.assert)(!(0, abort_js_1.isAbortError)(err));
|
|
76
80
|
(0, loggerRuntime_js_1.logRuntimeError)(err, httpRequestId);
|
|
77
81
|
const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
|
|
@@ -458,6 +462,6 @@ async function assertBaseUrl(pageContextInit, globalContext) {
|
|
|
458
462
|
const { baseServer } = globalContext;
|
|
459
463
|
const { urlOriginal } = pageContextInit;
|
|
460
464
|
const { urlWithoutPageContextRequestSuffix } = (0, handlePageContextRequestUrl_js_1.handlePageContextRequestUrl)(urlOriginal);
|
|
461
|
-
const {
|
|
462
|
-
(0, utils_js_1.assertUsage)(
|
|
465
|
+
const { isBaseMissing } = (0, utils_js_1.parseUrl)(urlWithoutPageContextRequestSuffix, baseServer);
|
|
466
|
+
(0, utils_js_1.assertUsage)(!isBaseMissing, `${picocolors_1.default.code('renderPage(pageContextInit)')} (https://vike.dev/renderPage) called with ${picocolors_1.default.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which doesn't start with Base URL ${picocolors_1.default.code(baseServer)} (https://vike.dev/base-url)`);
|
|
463
467
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = universalVikeHandler;
|
|
4
|
+
const index_js_1 = require("./index.js");
|
|
5
|
+
async function universalVikeHandler(request, context, runtime) {
|
|
6
|
+
const pageContextInit = { ...context, ...runtime, urlOriginal: request.url, headersOriginal: request.headers };
|
|
7
|
+
const pageContext = await (0, index_js_1.renderPage)(pageContextInit);
|
|
8
|
+
const response = pageContext.httpResponse;
|
|
9
|
+
const readable = response.getReadableWebStream();
|
|
10
|
+
return new Response(readable, {
|
|
11
|
+
status: response.statusCode,
|
|
12
|
+
headers: response.headers
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -88,8 +88,8 @@ function urlGetter() {
|
|
|
88
88
|
}
|
|
89
89
|
function urlParsedGetter() {
|
|
90
90
|
const {
|
|
91
|
-
// remove
|
|
92
|
-
|
|
91
|
+
// remove isBaseMissing as it isn't part of UrlPublic
|
|
92
|
+
isBaseMissing: _, ...urlParsed } = getUrlParsed(this);
|
|
93
93
|
const hashIsAvailable = (0, utils_js_1.isBrowser)();
|
|
94
94
|
const warnHashNotAvailable = (prop) => {
|
|
95
95
|
(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 });
|
package/dist/cjs/utils/assert.js
CHANGED
|
@@ -47,7 +47,7 @@ function assert(condition, debugInfo) {
|
|
|
47
47
|
const debugInfoSerialized = typeof debugInfo === 'string' ? debugInfo : JSON.stringify(debugInfo);
|
|
48
48
|
return picocolors_1.default.dim(`Debug info (for Vike maintainers; you can ignore this): ${debugInfoSerialized}`);
|
|
49
49
|
})();
|
|
50
|
-
const link = picocolors_1.default.blue('https://github.com/vikejs/vike/issues/new');
|
|
50
|
+
const link = picocolors_1.default.blue('https://github.com/vikejs/vike/issues/new?template=bug.yml');
|
|
51
51
|
let errMsg = [
|
|
52
52
|
`You stumbled upon a Vike bug. Go to ${link} and copy-paste this error. A maintainer will fix the bug (usually within 24 hours).`,
|
|
53
53
|
debugStr
|
|
@@ -30,8 +30,8 @@ function prependBase(url, baseServer) {
|
|
|
30
30
|
return `${baseServerNormalized}${url}`;
|
|
31
31
|
}
|
|
32
32
|
function removeBaseServer(url, baseServer) {
|
|
33
|
-
const {
|
|
34
|
-
(0, assert_js_1.assert)(
|
|
33
|
+
const { isBaseMissing, origin, pathname, pathnameOriginal, searchOriginal, hashOriginal } = (0, parseUrl_js_1.parseUrl)(url, baseServer);
|
|
34
|
+
(0, assert_js_1.assert)(!isBaseMissing);
|
|
35
35
|
(0, parseUrl_js_1.assertUrlComponents)(url, origin, pathnameOriginal, searchOriginal, hashOriginal);
|
|
36
36
|
const urlWithoutBase = (0, parseUrl_js_1.createUrlFromComponents)(origin, pathname, searchOriginal, hashOriginal);
|
|
37
37
|
return urlWithoutBase;
|
|
@@ -49,7 +49,7 @@ function parseUrl(url, baseServer) {
|
|
|
49
49
|
const pathnameOriginal = urlWithoutHashNorSearch.slice((origin || '').length);
|
|
50
50
|
assertUrlComponents(url, origin, pathnameOriginal, searchOriginal, hashOriginal);
|
|
51
51
|
// Base URL
|
|
52
|
-
let { pathname,
|
|
52
|
+
let { pathname, isBaseMissing } = removeBaseServer(pathnameAbsoluteWithBase, baseServer);
|
|
53
53
|
// pageContext.urlParsed.href
|
|
54
54
|
const href = createUrlFromComponents(origin, pathname, searchOriginal, hashOriginal);
|
|
55
55
|
// pageContext.urlParsed.{hostname, port}
|
|
@@ -66,7 +66,7 @@ function parseUrl(url, baseServer) {
|
|
|
66
66
|
origin,
|
|
67
67
|
pathname,
|
|
68
68
|
pathnameOriginal: pathnameOriginal,
|
|
69
|
-
|
|
69
|
+
isBaseMissing,
|
|
70
70
|
search,
|
|
71
71
|
searchAll,
|
|
72
72
|
searchOriginal,
|
|
@@ -235,7 +235,7 @@ function removeBaseServer(pathnameAbsoluteWithBase, baseServer) {
|
|
|
235
235
|
(0, assert_js_1.assert)(baseServer.startsWith('/'));
|
|
236
236
|
if (baseServer === '/') {
|
|
237
237
|
const pathname = pathnameAbsoluteWithBase;
|
|
238
|
-
return { pathname,
|
|
238
|
+
return { pathname, isBaseMissing: false };
|
|
239
239
|
}
|
|
240
240
|
// Support `url === '/some-base-url' && baseServer === '/some-base-url/'`
|
|
241
241
|
let baseServerNormalized = baseServer;
|
|
@@ -245,7 +245,7 @@ function removeBaseServer(pathnameAbsoluteWithBase, baseServer) {
|
|
|
245
245
|
}
|
|
246
246
|
if (!urlPathname.startsWith(baseServerNormalized)) {
|
|
247
247
|
const pathname = pathnameAbsoluteWithBase;
|
|
248
|
-
return { pathname,
|
|
248
|
+
return { pathname, isBaseMissing: true };
|
|
249
249
|
}
|
|
250
250
|
(0, assert_js_1.assert)(urlPathname.startsWith('/') || urlPathname.startsWith('http'));
|
|
251
251
|
(0, assert_js_1.assert)(urlPathname.startsWith(baseServerNormalized));
|
|
@@ -253,7 +253,7 @@ function removeBaseServer(pathnameAbsoluteWithBase, baseServer) {
|
|
|
253
253
|
if (!urlPathname.startsWith('/'))
|
|
254
254
|
urlPathname = '/' + urlPathname;
|
|
255
255
|
(0, assert_js_1.assert)(urlPathname.startsWith('/'));
|
|
256
|
-
return { pathname: urlPathname,
|
|
256
|
+
return { pathname: urlPathname, isBaseMissing: false };
|
|
257
257
|
}
|
|
258
258
|
function isBaseServer(baseServer) {
|
|
259
259
|
return baseServer.startsWith('/');
|
|
@@ -49,8 +49,8 @@ function isSameAsCurrentUrl(href) {
|
|
|
49
49
|
function hasBaseServer(href) {
|
|
50
50
|
const baseServer = getBaseServer();
|
|
51
51
|
assert(isBaseServer(baseServer));
|
|
52
|
-
const {
|
|
53
|
-
return
|
|
52
|
+
const { isBaseMissing } = parseUrl(href, baseServer);
|
|
53
|
+
return !isBaseMissing;
|
|
54
54
|
}
|
|
55
55
|
function isDisableAutomaticLinkInterception() {
|
|
56
56
|
// @ts-ignore
|
|
@@ -7,6 +7,9 @@ import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
|
|
|
7
7
|
import { getFullBuildInlineConfig } from '../shared/getFullBuildInlineConfig.js';
|
|
8
8
|
function buildApp() {
|
|
9
9
|
let config;
|
|
10
|
+
// `builder.buildApp` can be overriden by another plugin e.g vike-vercel https://github.com/vikejs/vike/pull/2184#issuecomment-2659425195
|
|
11
|
+
// In that case, we should'nt `forceExit`.
|
|
12
|
+
let forceExit = false;
|
|
10
13
|
return [
|
|
11
14
|
{
|
|
12
15
|
name: 'vike:buildApp',
|
|
@@ -21,6 +24,10 @@ function buildApp() {
|
|
|
21
24
|
assert(builder.environments.ssr);
|
|
22
25
|
await builder.build(builder.environments.client);
|
|
23
26
|
await builder.build(builder.environments.ssr);
|
|
27
|
+
if (forceExit) {
|
|
28
|
+
runPrerender_forceExit();
|
|
29
|
+
assert(false);
|
|
30
|
+
}
|
|
24
31
|
}
|
|
25
32
|
},
|
|
26
33
|
environments: {
|
|
@@ -59,11 +66,8 @@ function buildApp() {
|
|
|
59
66
|
if (!isPrerenderAutoRunEnabled(vikeConfig))
|
|
60
67
|
return;
|
|
61
68
|
const configInline = getFullBuildInlineConfig(config);
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
runPrerender_forceExit();
|
|
65
|
-
assert(false);
|
|
66
|
-
}
|
|
69
|
+
const res = await runPrerenderFromAutoRun(configInline, config);
|
|
70
|
+
forceExit = res.forceExit;
|
|
67
71
|
}
|
|
68
72
|
}
|
|
69
73
|
];
|
|
@@ -80,6 +80,9 @@ function buildConfig() {
|
|
|
80
80
|
{
|
|
81
81
|
name: 'vike:buildConfig:pre',
|
|
82
82
|
apply: 'build',
|
|
83
|
+
applyToEnvironment(env) {
|
|
84
|
+
return env.name === 'ssr';
|
|
85
|
+
},
|
|
83
86
|
// Make sure other writeBundle() hooks are called after this writeBundle() hook.
|
|
84
87
|
// - set_ASSETS_MANIFEST() needs to be called before dist/server/ code is executed.
|
|
85
88
|
// - For example, the writeBundle() hook of vite-plugin-vercel needs to be called after this writeBundle() hook, otherwise: https://github.com/vikejs/vike/issues/1527
|
|
@@ -4,6 +4,7 @@ import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, isArr
|
|
|
4
4
|
import { sourceMapPassthrough } from '../shared/rollupSourceMap.js';
|
|
5
5
|
import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
|
|
6
6
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
7
|
+
import { viteIsSSR_safe } from '../shared/viteIsSSR.js';
|
|
7
8
|
// TODO/enventually: (after we implemented vike.config.js)
|
|
8
9
|
// - Make import.meta.env work inside +config.js
|
|
9
10
|
// - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
|
|
@@ -36,7 +37,7 @@ function envVarsPlugin() {
|
|
|
36
37
|
if (!code.includes('import.meta.env.'))
|
|
37
38
|
return;
|
|
38
39
|
const isBuild = config.command === 'build';
|
|
39
|
-
const isClientSide =
|
|
40
|
+
const isClientSide = !viteIsSSR_safe(config, options);
|
|
40
41
|
Object.entries(envsAll)
|
|
41
42
|
.filter(([key]) => {
|
|
42
43
|
// Already handled by Vite
|
|
@@ -82,20 +83,3 @@ function envVarsPlugin() {
|
|
|
82
83
|
function applyEnvVar(envStatementRegEx, envVal, code) {
|
|
83
84
|
return code.replace(envStatementRegEx, JSON.stringify(envVal));
|
|
84
85
|
}
|
|
85
|
-
function getIsClientSide(config, options) {
|
|
86
|
-
const isBuild = config.command === 'build';
|
|
87
|
-
if (isBuild) {
|
|
88
|
-
assert(typeof config.build.ssr === 'boolean');
|
|
89
|
-
const isServerSide = config.build.ssr;
|
|
90
|
-
if (options !== undefined) {
|
|
91
|
-
assert(options.ssr === isServerSide);
|
|
92
|
-
}
|
|
93
|
-
return !isServerSide;
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
assert(config.build.ssr === false);
|
|
97
|
-
assert(typeof options?.ssr === 'boolean');
|
|
98
|
-
const isServerSide = options.ssr;
|
|
99
|
-
return !isServerSide;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
@@ -17,7 +17,7 @@ import { fixServerAssets_isEnabled } from './buildConfig/fixServerAssets.js';
|
|
|
17
17
|
import { getVikeConfig, isV1Design } from './importUserCode/v1-design/getVikeConfig.js';
|
|
18
18
|
import { assertV1Design } from '../../shared/assertV1Design.js';
|
|
19
19
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
20
|
-
import {
|
|
20
|
+
import { viteIsSSR_safe } from '../shared/viteIsSSR.js';
|
|
21
21
|
const extractAssetsRE = /(\?|&)extractAssets(?:&|$)/;
|
|
22
22
|
const rawRE = /(\?|&)raw(?:&|$)/;
|
|
23
23
|
const urlRE = /(\?|&)url(?:&|$)/;
|
|
@@ -46,7 +46,7 @@ function extractAssetsPlugin() {
|
|
|
46
46
|
}
|
|
47
47
|
// TODO/now: add meta.default
|
|
48
48
|
assert(vikeConfig.global.config.includeAssetsImportedByServer ?? true);
|
|
49
|
-
assert(!
|
|
49
|
+
assert(!viteIsSSR_safe(config, options));
|
|
50
50
|
const importStatements = await getImportStatements(src);
|
|
51
51
|
const moduleNames = getImportedModules(importStatements);
|
|
52
52
|
const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
|
|
@@ -63,7 +63,7 @@ function extractAssetsPlugin() {
|
|
|
63
63
|
// - Vite's `vite:resolve` plugin; https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
|
|
64
64
|
enforce: 'pre',
|
|
65
65
|
async resolveId(source, importer, options) {
|
|
66
|
-
if (
|
|
66
|
+
if (viteIsSSR_safe(config, options)) {
|
|
67
67
|
// When building for the server, there should never be a `?extractAssets` query
|
|
68
68
|
assert(!extractAssetsRE.test(source));
|
|
69
69
|
assert(importer === undefined || !extractAssetsRE.test(importer));
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// - We dedupe errors ourself with getHttpRequestAsyncStore().shouldErrorBeSwallowed()
|
|
11
11
|
export { getHttpRequestAsyncStore };
|
|
12
12
|
export { installHttpRequestAsyncStore };
|
|
13
|
-
import {
|
|
13
|
+
import { renderPage_addAsyncHookwrapper } from '../../runtime/renderPage.js';
|
|
14
14
|
import { assert, assertIsNotProductionRuntime, isObject, unique } from '../utils.js';
|
|
15
15
|
import { getConfigBuildErrorFormatted } from '../plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js';
|
|
16
16
|
import { logErrorDebugNote } from './loggerNotProd.js';
|
|
@@ -27,7 +27,7 @@ async function installHttpRequestAsyncStore() {
|
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
asyncLocalStorage = new mod.AsyncLocalStorage();
|
|
30
|
-
|
|
30
|
+
renderPage_addAsyncHookwrapper(async (httpRequestId, renderPage) => {
|
|
31
31
|
assert(asyncLocalStorage);
|
|
32
32
|
const loggedErrors = new Set();
|
|
33
33
|
const markErrorAsLogged = (err) => {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import type { ResolvedConfig, UserConfig } from 'vite';
|
|
2
1
|
export { viteIsSSR };
|
|
3
2
|
export { viteIsSSR_options };
|
|
3
|
+
export { viteIsSSR_safe };
|
|
4
|
+
import type { ResolvedConfig, UserConfig } from 'vite';
|
|
4
5
|
declare function viteIsSSR(config: ResolvedConfig | UserConfig): boolean;
|
|
5
|
-
|
|
6
|
+
declare function viteIsSSR_options(options: {
|
|
7
|
+
ssr?: boolean;
|
|
8
|
+
} | undefined): boolean;
|
|
9
|
+
declare function viteIsSSR_safe(config: ResolvedConfig, options: {
|
|
6
10
|
ssr?: boolean;
|
|
7
|
-
};
|
|
8
|
-
declare function viteIsSSR_options(options: Options): boolean;
|
|
11
|
+
} | undefined): boolean;
|
|
@@ -1,20 +1,29 @@
|
|
|
1
|
-
import { assert } from '../../../utils/assert.js';
|
|
2
|
-
import { isObject } from '../../../utils/isObject.js';
|
|
3
1
|
export { viteIsSSR };
|
|
4
2
|
export { viteIsSSR_options };
|
|
3
|
+
export { viteIsSSR_safe };
|
|
4
|
+
import { assert } from '../../../utils/assert.js';
|
|
5
5
|
function viteIsSSR(config) {
|
|
6
6
|
return !!config?.build?.ssr;
|
|
7
7
|
}
|
|
8
|
-
// https://github.com/vitejs/vite/discussions/5109#discussioncomment-1450726
|
|
9
8
|
function viteIsSSR_options(options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
return !!options?.ssr;
|
|
10
|
+
}
|
|
11
|
+
// Vite is quite messy about setting `ssr: boolean`, thus we use an extra safe implemention for security purposes.
|
|
12
|
+
// It's used for .client.js and .server.js guarantee thus we use agressive assert() calls for added safety.
|
|
13
|
+
function viteIsSSR_safe(config, options) {
|
|
14
|
+
if (config.command === 'build') {
|
|
15
|
+
assert(typeof config.build.ssr === 'boolean');
|
|
16
|
+
const val = config.build.ssr;
|
|
17
|
+
if (options?.ssr !== undefined)
|
|
18
|
+
assert(val === options.ssr);
|
|
19
|
+
return val;
|
|
15
20
|
}
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
else {
|
|
22
|
+
assert(typeof options?.ssr === 'boolean');
|
|
23
|
+
const val = options.ssr;
|
|
24
|
+
/* This assert() fails (which is very unexpected).
|
|
25
|
+
if (typeof config.build.ssr === 'boolean') assert(val === config.build.ssr)
|
|
26
|
+
//*/
|
|
27
|
+
return val;
|
|
18
28
|
}
|
|
19
|
-
assert(false);
|
|
20
29
|
}
|
|
@@ -124,7 +124,7 @@ function getViteConfig() {
|
|
|
124
124
|
}
|
|
125
125
|
async function initGlobalContext_renderPage() {
|
|
126
126
|
debug('initGlobalContext_renderPage()');
|
|
127
|
-
// globalObject.isProduction
|
|
127
|
+
// `globalObject.isProduction === undefined` when using production server without `vike-server`. (There isn't any reliable signal we can use to determine early whether the environement is production or development.)
|
|
128
128
|
if (globalObject.isProduction === undefined)
|
|
129
129
|
setIsProduction(true);
|
|
130
130
|
await initGlobalContext();
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
export { renderPage };
|
|
2
|
-
export {
|
|
2
|
+
export { renderPage_addAsyncHookwrapper };
|
|
3
3
|
import { HttpResponse } from './renderPage/createHttpResponse.js';
|
|
4
4
|
import type { PageContextServer } from '../../types/index.js';
|
|
5
|
-
declare let renderPage_wrapper: <PageContext>(_httpRequestId: number, ret: () => Promise<PageContext>) => Promise<{
|
|
6
|
-
pageContextReturn: Awaited<PageContext>;
|
|
7
|
-
}>;
|
|
8
|
-
declare const renderPage_addWrapper: (wrapper: typeof renderPage_wrapper) => void;
|
|
9
5
|
declare function renderPage<PageContextUserAdded extends {}, PageContextInit extends {
|
|
10
6
|
/** @deprecated */
|
|
11
7
|
url?: string;
|
|
@@ -14,3 +10,7 @@ declare function renderPage<PageContextUserAdded extends {}, PageContextInit ext
|
|
|
14
10
|
}>(pageContextInit: PageContextInit): Promise<PageContextInit & {
|
|
15
11
|
httpResponse: HttpResponse;
|
|
16
12
|
} & Partial<PageContextServer & PageContextUserAdded>>;
|
|
13
|
+
declare let asyncHookWrapper: <PageContext>(_httpRequestId: number, ret: () => Promise<PageContext>) => Promise<{
|
|
14
|
+
pageContextReturn: Awaited<PageContext>;
|
|
15
|
+
}>;
|
|
16
|
+
declare function renderPage_addAsyncHookwrapper(wrapper: typeof asyncHookWrapper): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { renderPage };
|
|
2
|
-
export {
|
|
2
|
+
export { renderPage_addAsyncHookwrapper };
|
|
3
3
|
import { getPageContextInitEnhanced, renderPageAlreadyRouted } from './renderPage/renderPageAlreadyRouted.js';
|
|
4
4
|
import { route } from '../../shared/route/index.js';
|
|
5
5
|
import { assert, hasProp, objectAssign, isUrl, parseUrl, onSetupRuntime, assertWarning, getGlobalObject, checkType, assertUsage, normalizeUrlPathname, removeBaseServer, modifyUrlPathname, prependBase, removeUrlOrigin, setUrlOrigin, createUrlFromComponents, isUri, getUrlPretty } from './utils.js';
|
|
@@ -21,12 +21,6 @@ import { resolveRedirects } from './renderPage/resolveRedirects.js';
|
|
|
21
21
|
const globalObject = getGlobalObject('runtime/renderPage.ts', {
|
|
22
22
|
httpRequestsCount: 0
|
|
23
23
|
});
|
|
24
|
-
let renderPage_wrapper = async (_httpRequestId, ret) => ({
|
|
25
|
-
pageContextReturn: await ret()
|
|
26
|
-
});
|
|
27
|
-
const renderPage_addWrapper = (wrapper) => {
|
|
28
|
-
renderPage_wrapper = wrapper;
|
|
29
|
-
};
|
|
30
24
|
// `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.)
|
|
31
25
|
async function renderPage(pageContextInit) {
|
|
32
26
|
assertArguments(...arguments);
|
|
@@ -40,12 +34,20 @@ async function renderPage(pageContextInit) {
|
|
|
40
34
|
const httpRequestId = getRequestId();
|
|
41
35
|
const urlOriginalPretty = getUrlPretty(pageContextInit.urlOriginal);
|
|
42
36
|
logHttpRequest(urlOriginalPretty, httpRequestId);
|
|
43
|
-
const { pageContextReturn } = await
|
|
37
|
+
const { pageContextReturn } = await asyncHookWrapper(httpRequestId, () => renderPageAndPrepare(pageContextInit, httpRequestId));
|
|
44
38
|
logHttpResponse(urlOriginalPretty, httpRequestId, pageContextReturn);
|
|
45
39
|
checkType(pageContextReturn);
|
|
46
40
|
assert(pageContextReturn.httpResponse);
|
|
47
41
|
return pageContextReturn;
|
|
48
42
|
}
|
|
43
|
+
// Fallback wrapper if node:async_hooks isn't available
|
|
44
|
+
let asyncHookWrapper = async (_httpRequestId, ret) => ({
|
|
45
|
+
pageContextReturn: await ret()
|
|
46
|
+
});
|
|
47
|
+
// Add node:async_hooks wrapper
|
|
48
|
+
function renderPage_addAsyncHookwrapper(wrapper) {
|
|
49
|
+
asyncHookWrapper = wrapper;
|
|
50
|
+
}
|
|
49
51
|
async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
50
52
|
// Invalid config
|
|
51
53
|
const handleInvalidConfig = (err) => {
|
|
@@ -64,8 +66,11 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
|
64
66
|
await initGlobalContext_renderPage();
|
|
65
67
|
}
|
|
66
68
|
catch (err) {
|
|
67
|
-
// Errors are expected since assertUsage() is used in
|
|
68
|
-
//
|
|
69
|
+
// Errors are expected since assertUsage() is used in initGlobalContext_renderPage() such as:
|
|
70
|
+
// ```bash
|
|
71
|
+
// Re-build your app (you're using 1.2.3 but your app was built with 1.2.2)
|
|
72
|
+
// ```
|
|
73
|
+
// initGlobalContext_renderPage() doens't call any user hook => err isn't thrown from user code.
|
|
69
74
|
assert(!isAbortError(err));
|
|
70
75
|
logRuntimeError(err, httpRequestId);
|
|
71
76
|
const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
|
|
@@ -452,6 +457,6 @@ async function assertBaseUrl(pageContextInit, globalContext) {
|
|
|
452
457
|
const { baseServer } = globalContext;
|
|
453
458
|
const { urlOriginal } = pageContextInit;
|
|
454
459
|
const { urlWithoutPageContextRequestSuffix } = handlePageContextRequestUrl(urlOriginal);
|
|
455
|
-
const {
|
|
456
|
-
assertUsage(
|
|
460
|
+
const { isBaseMissing } = parseUrl(urlWithoutPageContextRequestSuffix, baseServer);
|
|
461
|
+
assertUsage(!isBaseMissing, `${pc.code('renderPage(pageContextInit)')} (https://vike.dev/renderPage) called with ${pc.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which doesn't start with Base URL ${pc.code(baseServer)} (https://vike.dev/base-url)`);
|
|
457
462
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function universalVikeHandler(request: Request, context: Record<string, unknown>, runtime: Record<string, unknown>): Promise<Response>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { renderPage } from './index.js';
|
|
2
|
+
export default async function universalVikeHandler(request, context, runtime) {
|
|
3
|
+
const pageContextInit = { ...context, ...runtime, urlOriginal: request.url, headersOriginal: request.headers };
|
|
4
|
+
const pageContext = await renderPage(pageContextInit);
|
|
5
|
+
const response = pageContext.httpResponse;
|
|
6
|
+
const readable = response.getReadableWebStream();
|
|
7
|
+
return new Response(readable, {
|
|
8
|
+
status: response.statusCode,
|
|
9
|
+
headers: response.headers
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -86,8 +86,8 @@ function urlGetter() {
|
|
|
86
86
|
}
|
|
87
87
|
function urlParsedGetter() {
|
|
88
88
|
const {
|
|
89
|
-
// remove
|
|
90
|
-
|
|
89
|
+
// remove isBaseMissing as it isn't part of UrlPublic
|
|
90
|
+
isBaseMissing: _, ...urlParsed } = getUrlParsed(this);
|
|
91
91
|
const hashIsAvailable = isBrowser();
|
|
92
92
|
const warnHashNotAvailable = (prop) => {
|
|
93
93
|
assertWarning(hashIsAvailable, `pageContext.urlParsed.${prop} isn't available on the server-side (HTTP requests don't include the URL hash)`, { onlyOnce: true, showStackTrace: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.222-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.222-commit-ce4e16e";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.222-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.222-commit-ce4e16e';
|
package/dist/esm/utils/assert.js
CHANGED
|
@@ -42,7 +42,7 @@ function assert(condition, debugInfo) {
|
|
|
42
42
|
const debugInfoSerialized = typeof debugInfo === 'string' ? debugInfo : JSON.stringify(debugInfo);
|
|
43
43
|
return pc.dim(`Debug info (for Vike maintainers; you can ignore this): ${debugInfoSerialized}`);
|
|
44
44
|
})();
|
|
45
|
-
const link = pc.blue('https://github.com/vikejs/vike/issues/new');
|
|
45
|
+
const link = pc.blue('https://github.com/vikejs/vike/issues/new?template=bug.yml');
|
|
46
46
|
let errMsg = [
|
|
47
47
|
`You stumbled upon a Vike bug. Go to ${link} and copy-paste this error. A maintainer will fix the bug (usually within 24 hours).`,
|
|
48
48
|
debugStr
|
|
@@ -28,8 +28,8 @@ function prependBase(url, baseServer) {
|
|
|
28
28
|
return `${baseServerNormalized}${url}`;
|
|
29
29
|
}
|
|
30
30
|
function removeBaseServer(url, baseServer) {
|
|
31
|
-
const {
|
|
32
|
-
assert(
|
|
31
|
+
const { isBaseMissing, origin, pathname, pathnameOriginal, searchOriginal, hashOriginal } = parseUrl(url, baseServer);
|
|
32
|
+
assert(!isBaseMissing);
|
|
33
33
|
assertUrlComponents(url, origin, pathnameOriginal, searchOriginal, hashOriginal);
|
|
34
34
|
const urlWithoutBase = createUrlFromComponents(origin, pathname, searchOriginal, hashOriginal);
|
|
35
35
|
return urlWithoutBase;
|
|
@@ -10,7 +10,6 @@ export { isBaseServer };
|
|
|
10
10
|
export { assertUrlComponents };
|
|
11
11
|
export { createUrlFromComponents };
|
|
12
12
|
export type { UrlPublic };
|
|
13
|
-
export type { UrlPrivate };
|
|
14
13
|
type UrlPublic = {
|
|
15
14
|
/** The full URL. */
|
|
16
15
|
href: string;
|
|
@@ -41,10 +40,10 @@ type UrlPublic = {
|
|
|
41
40
|
/** @deprecated */
|
|
42
41
|
searchString: null | string;
|
|
43
42
|
};
|
|
44
|
-
type
|
|
45
|
-
|
|
43
|
+
type UrlInternal = Omit<UrlPublic, 'hashString' | 'searchString'> & {
|
|
44
|
+
isBaseMissing: boolean;
|
|
46
45
|
};
|
|
47
|
-
declare function parseUrl(url: string, baseServer: string):
|
|
46
|
+
declare function parseUrl(url: string, baseServer: string): UrlInternal;
|
|
48
47
|
declare function isBaseServer(baseServer: string): boolean;
|
|
49
48
|
declare function assertUrlComponents(url: string, origin: string | null, pathnameOriginal: string, searchOriginal: string | null, hashOriginal: string | null): void;
|
|
50
49
|
declare function createUrlFromComponents(origin: string | null, pathname: string, search: string | null, hash: string | null): string;
|
|
@@ -45,7 +45,7 @@ function parseUrl(url, baseServer) {
|
|
|
45
45
|
const pathnameOriginal = urlWithoutHashNorSearch.slice((origin || '').length);
|
|
46
46
|
assertUrlComponents(url, origin, pathnameOriginal, searchOriginal, hashOriginal);
|
|
47
47
|
// Base URL
|
|
48
|
-
let { pathname,
|
|
48
|
+
let { pathname, isBaseMissing } = removeBaseServer(pathnameAbsoluteWithBase, baseServer);
|
|
49
49
|
// pageContext.urlParsed.href
|
|
50
50
|
const href = createUrlFromComponents(origin, pathname, searchOriginal, hashOriginal);
|
|
51
51
|
// pageContext.urlParsed.{hostname, port}
|
|
@@ -62,7 +62,7 @@ function parseUrl(url, baseServer) {
|
|
|
62
62
|
origin,
|
|
63
63
|
pathname,
|
|
64
64
|
pathnameOriginal: pathnameOriginal,
|
|
65
|
-
|
|
65
|
+
isBaseMissing,
|
|
66
66
|
search,
|
|
67
67
|
searchAll,
|
|
68
68
|
searchOriginal,
|
|
@@ -231,7 +231,7 @@ function removeBaseServer(pathnameAbsoluteWithBase, baseServer) {
|
|
|
231
231
|
assert(baseServer.startsWith('/'));
|
|
232
232
|
if (baseServer === '/') {
|
|
233
233
|
const pathname = pathnameAbsoluteWithBase;
|
|
234
|
-
return { pathname,
|
|
234
|
+
return { pathname, isBaseMissing: false };
|
|
235
235
|
}
|
|
236
236
|
// Support `url === '/some-base-url' && baseServer === '/some-base-url/'`
|
|
237
237
|
let baseServerNormalized = baseServer;
|
|
@@ -241,7 +241,7 @@ function removeBaseServer(pathnameAbsoluteWithBase, baseServer) {
|
|
|
241
241
|
}
|
|
242
242
|
if (!urlPathname.startsWith(baseServerNormalized)) {
|
|
243
243
|
const pathname = pathnameAbsoluteWithBase;
|
|
244
|
-
return { pathname,
|
|
244
|
+
return { pathname, isBaseMissing: true };
|
|
245
245
|
}
|
|
246
246
|
assert(urlPathname.startsWith('/') || urlPathname.startsWith('http'));
|
|
247
247
|
assert(urlPathname.startsWith(baseServerNormalized));
|
|
@@ -249,7 +249,7 @@ function removeBaseServer(pathnameAbsoluteWithBase, baseServer) {
|
|
|
249
249
|
if (!urlPathname.startsWith('/'))
|
|
250
250
|
urlPathname = '/' + urlPathname;
|
|
251
251
|
assert(urlPathname.startsWith('/'));
|
|
252
|
-
return { pathname: urlPathname,
|
|
252
|
+
return { pathname: urlPathname, isBaseMissing: false };
|
|
253
253
|
}
|
|
254
254
|
function isBaseServer(baseServer) {
|
|
255
255
|
return baseServer.startsWith('/');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.222-commit-
|
|
3
|
+
"version": "0.4.222-commit-ce4e16e",
|
|
4
4
|
"repository": "https://github.com/vikejs/vike",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": {
|
|
@@ -96,6 +96,15 @@
|
|
|
96
96
|
"types": "./dist/esm/shared/modifyUrl.d.ts",
|
|
97
97
|
"default": "./dist/esm/shared/modifyUrl.js"
|
|
98
98
|
},
|
|
99
|
+
"./universal-middleware": {
|
|
100
|
+
"worker": "./dist/esm/node/runtime/universal-middleware.js",
|
|
101
|
+
"edge-light": "./dist/esm/node/runtime/universal-middleware.js",
|
|
102
|
+
"require": "./dist/cjs/node/runtime/universal-middleware.js",
|
|
103
|
+
"node": "./dist/esm/node/runtime/universal-middleware.js",
|
|
104
|
+
"browser": "./dist/esm/client/node.js",
|
|
105
|
+
"types": "./dist/esm/node/runtime/universal-middleware.d.ts",
|
|
106
|
+
"default": "./dist/esm/node/runtime/universal-middleware.js"
|
|
107
|
+
},
|
|
99
108
|
"./__internal": {
|
|
100
109
|
"require": "./dist/cjs/__internal/index.js",
|
|
101
110
|
"node": "./dist/esm/__internal/index.js",
|
|
@@ -203,6 +212,9 @@
|
|
|
203
212
|
"modifyUrl": [
|
|
204
213
|
"./dist/esm/shared/modifyUrl.d.ts"
|
|
205
214
|
],
|
|
215
|
+
"universal-middleware": [
|
|
216
|
+
"./dist/esm/node/runtime/universal-middleware.d.ts"
|
|
217
|
+
],
|
|
206
218
|
"__internal": [
|
|
207
219
|
"./dist/esm/__internal/index.d.ts"
|
|
208
220
|
],
|
|
@@ -235,7 +247,8 @@
|
|
|
235
247
|
"./RenderErrorPage.js",
|
|
236
248
|
"./routing.js",
|
|
237
249
|
"./server.js",
|
|
238
|
-
"./types.js"
|
|
250
|
+
"./types.js",
|
|
251
|
+
"./universal-middleware.js"
|
|
239
252
|
],
|
|
240
253
|
"devDependencies": {
|
|
241
254
|
"@biomejs/biome": "^1.5.3",
|