vike 0.4.222-commit-207e079 → 0.4.222
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/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -6
- package/dist/cjs/node/runtime/globalContext.js +6 -17
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +4 -2
- package/dist/cjs/node/runtime/renderPage.js +8 -4
- package/dist/cjs/node/shared/resolveBase.js +13 -0
- package/dist/cjs/shared/route/loadPageRoutes.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSingleInstance.js +1 -1
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +1 -1
- package/dist/esm/node/plugin/index.d.ts +1 -4
- package/dist/esm/node/plugin/index.js +1 -1
- package/dist/esm/node/plugin/plugins/baseUrls.js +1 -6
- package/dist/esm/node/runtime/globalContext.d.ts +6 -7
- package/dist/esm/node/runtime/globalContext.js +6 -17
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.d.ts +2 -2
- package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +8 -8
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +4 -2
- package/dist/esm/node/runtime/renderPage.js +8 -4
- package/dist/esm/node/shared/resolveBase.d.ts +9 -1
- package/dist/esm/node/shared/resolveBase.js +13 -0
- package/dist/esm/shared/route/loadPageRoutes.js +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/assertSingleInstance.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
|
@@ -35,7 +35,7 @@ const workaroundVite6HmrRegression_js_1 = require("./plugins/workaroundVite6HmrR
|
|
|
35
35
|
const buildApp_js_1 = require("./plugins/buildApp.js");
|
|
36
36
|
// We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
|
|
37
37
|
(0, getPageAssets_js_1.setResolveClientEntriesDev)(resolveClientEntriesDev_js_1.resolveClientEntriesDev);
|
|
38
|
-
// Return
|
|
38
|
+
// Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
|
|
39
39
|
function plugin(vikeVitePluginOptions = {}) {
|
|
40
40
|
const plugins = [
|
|
41
41
|
...(0, commonConfig_js_1.commonConfig)(vikeVitePluginOptions),
|
|
@@ -29,7 +29,7 @@ function baseUrls() {
|
|
|
29
29
|
},
|
|
30
30
|
async configResolved(config) {
|
|
31
31
|
const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(config);
|
|
32
|
-
const basesResolved2 = resolveBaseFromResolvedConfig(vikeConfig.global.config.baseServer ?? null, vikeConfig.global.config.baseAssets ?? null, config);
|
|
32
|
+
const basesResolved2 = (0, resolveBase_js_1.resolveBaseFromResolvedConfig)(vikeConfig.global.config.baseServer ?? null, vikeConfig.global.config.baseAssets ?? null, config);
|
|
33
33
|
(0, utils_js_1.assert)(basesResolved2.baseServer === basesResolved.baseServer);
|
|
34
34
|
(0, utils_js_1.assert)(basesResolved2.baseAssets === basesResolved.baseAssets);
|
|
35
35
|
/* In dev, Vite seems buggy around setting vite.config.js#base to an absolute URL (e.g. http://localhost:8080/cdn/)
|
|
@@ -40,8 +40,3 @@ function baseUrls() {
|
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
-
function resolveBaseFromResolvedConfig(baseServer, baseAssets, config) {
|
|
44
|
-
let baseViteOriginal = config._baseViteOriginal;
|
|
45
|
-
(0, utils_js_1.assert)(baseViteOriginal === null || typeof baseViteOriginal == 'string');
|
|
46
|
-
return (0, resolveBase_js_1.resolveBase)(baseViteOriginal, baseServer, baseAssets);
|
|
47
|
-
}
|
|
@@ -21,7 +21,7 @@ exports.assertBuildInfo = assertBuildInfo;
|
|
|
21
21
|
exports.getViteConfigRuntime = getViteConfigRuntime;
|
|
22
22
|
exports.updateUserFiles = updateUserFiles;
|
|
23
23
|
// The core logic revolves around:
|
|
24
|
-
// - globalObject.userFiles which is the main requirement for
|
|
24
|
+
// - globalObject.userFiles which is the main requirement for assembleGlobalContext()
|
|
25
25
|
// - In production: globalObject.buildEntry which is the production entry set by @brillout/vite-plugin-server-entry
|
|
26
26
|
// - loadBuildEntry() sets globalObject.buildEntry and then sets globalObject.userFiles
|
|
27
27
|
// - With vike-server it's set at server start: @brillout/vite-plugin-server-entry injects `import './entry.mjs'` (the production entry generated by @brillout/vite-plugin-server-entry) as first line of code of dist/server/index.mjs while dist/server/entry.mjs calls setGlobalContext_buildEntry()
|
|
@@ -35,7 +35,6 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
35
35
|
const loadPageRoutes_js_1 = require("../../shared/route/loadPageRoutes.js");
|
|
36
36
|
const assertV1Design_js_1 = require("../shared/assertV1Design.js");
|
|
37
37
|
const getPageConfigsRuntime_js_1 = require("../../shared/getPageConfigsRuntime.js");
|
|
38
|
-
const resolveBase_js_1 = require("../shared/resolveBase.js");
|
|
39
38
|
const debug = (0, utils_js_1.createDebugger)('vike:globalContext');
|
|
40
39
|
const globalObject = (0, utils_js_1.getGlobalObject)('globalContext.ts', getInitialGlobalContext());
|
|
41
40
|
async function getGlobalContextInternal() {
|
|
@@ -83,9 +82,7 @@ function makePublic(globalContext) {
|
|
|
83
82
|
'assetsManifest',
|
|
84
83
|
'config',
|
|
85
84
|
'viteConfig',
|
|
86
|
-
'pages'
|
|
87
|
-
'baseServer',
|
|
88
|
-
'baseAssets'
|
|
85
|
+
'pages'
|
|
89
86
|
]);
|
|
90
87
|
return globalContextPublic;
|
|
91
88
|
}
|
|
@@ -190,7 +187,7 @@ function setIsProduction(isProduction) {
|
|
|
190
187
|
globalObject.isProduction = isProduction;
|
|
191
188
|
}
|
|
192
189
|
function defineGlobalContext() {
|
|
193
|
-
const globalContext =
|
|
190
|
+
const globalContext = assembleGlobalContext();
|
|
194
191
|
assertIsDefined(globalContext);
|
|
195
192
|
const globalContext_public = makePublic(globalContext);
|
|
196
193
|
(0, utils_js_1.objectAssign)(globalContext, { globalContext_public });
|
|
@@ -199,7 +196,7 @@ function defineGlobalContext() {
|
|
|
199
196
|
assertGlobalContextIsDefined();
|
|
200
197
|
(0, utils_js_1.onSetupRuntime)();
|
|
201
198
|
}
|
|
202
|
-
function
|
|
199
|
+
function assembleGlobalContext() {
|
|
203
200
|
const { viteDevServer, viteConfig, isPrerendering, isProduction, userFiles } = globalObject;
|
|
204
201
|
(0, utils_js_1.assert)(typeof isProduction === 'boolean');
|
|
205
202
|
let globalContext;
|
|
@@ -218,8 +215,7 @@ function resolveGlobalContext() {
|
|
|
218
215
|
viteDevServer,
|
|
219
216
|
viteConfig,
|
|
220
217
|
...userFiles,
|
|
221
|
-
viteConfigRuntime
|
|
222
|
-
...resolveBaseRuntime(viteConfigRuntime, userFiles.config)
|
|
218
|
+
viteConfigRuntime
|
|
223
219
|
};
|
|
224
220
|
}
|
|
225
221
|
else {
|
|
@@ -236,8 +232,7 @@ function resolveGlobalContext() {
|
|
|
236
232
|
...userFiles,
|
|
237
233
|
viteDevServer: null,
|
|
238
234
|
viteConfigRuntime: buildInfo.viteConfigRuntime,
|
|
239
|
-
usesClientRouter: buildInfo.usesClientRouter
|
|
240
|
-
...resolveBaseRuntime(buildInfo.viteConfigRuntime, userFiles.config)
|
|
235
|
+
usesClientRouter: buildInfo.usesClientRouter
|
|
241
236
|
};
|
|
242
237
|
if (isPrerendering) {
|
|
243
238
|
(0, utils_js_1.assert)(viteConfig);
|
|
@@ -406,9 +401,3 @@ function getInitialGlobalContext() {
|
|
|
406
401
|
viteDevServerPromiseResolve
|
|
407
402
|
};
|
|
408
403
|
}
|
|
409
|
-
function resolveBaseRuntime(viteConfigRuntime, config) {
|
|
410
|
-
const baseViteOriginal = viteConfigRuntime._baseViteOriginal;
|
|
411
|
-
const baseServerUnresolved = config.baseServer ?? null;
|
|
412
|
-
const baseAssetsUnresolved = config.baseAssets ?? null;
|
|
413
|
-
return (0, resolveBase_js_1.resolveBase)(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved);
|
|
414
|
-
}
|
|
@@ -22,6 +22,7 @@ const preparePageContextForUserConsumptionServerSide_js_1 = require("./preparePa
|
|
|
22
22
|
const executeGuardHook_js_1 = require("../../../shared/route/executeGuardHook.js");
|
|
23
23
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
24
24
|
const isServerSideError_js_1 = require("../../../shared/misc/isServerSideError.js");
|
|
25
|
+
const resolveBase_js_1 = require("../../shared/resolveBase.js");
|
|
25
26
|
async function renderPageAlreadyRouted(pageContext) {
|
|
26
27
|
// pageContext.pageId can either be the:
|
|
27
28
|
// - ID of the page matching the routing, or the
|
|
@@ -116,13 +117,14 @@ async function getPageContextInitEnhanced(pageContextInit, globalContext, { ssr:
|
|
|
116
117
|
isClientSideNavigation: false
|
|
117
118
|
} } = {}) {
|
|
118
119
|
(0, utils_js_1.assert)(pageContextInit.urlOriginal);
|
|
120
|
+
const { baseServer, baseAssets } = (0, resolveBase_js_1.resolveBaseRuntime)(globalContext);
|
|
119
121
|
const pageContextInitEnhanced = {};
|
|
120
122
|
(0, utils_js_1.objectAssign)(pageContextInitEnhanced, pageContextInit);
|
|
121
123
|
(0, utils_js_1.objectAssign)(pageContextInitEnhanced, {
|
|
122
124
|
_objectCreatedByVike: true,
|
|
123
125
|
// The following is defined on `pageContext` because we can eventually make these non-global
|
|
124
|
-
_baseServer:
|
|
125
|
-
_baseAssets:
|
|
126
|
+
_baseServer: baseServer,
|
|
127
|
+
_baseAssets: baseAssets,
|
|
126
128
|
// TODO/now: add meta.default
|
|
127
129
|
_includeAssetsImportedByServer: globalContext.config.includeAssetsImportedByServer ?? true,
|
|
128
130
|
// TODO/soon: use GloablContext instead
|
|
@@ -23,6 +23,7 @@ const error_page_js_1 = require("../../shared/error-page.js");
|
|
|
23
23
|
const handleErrorWithoutErrorPage_js_1 = require("./renderPage/handleErrorWithoutErrorPage.js");
|
|
24
24
|
const loadUserFilesServerSide_js_1 = require("./renderPage/loadUserFilesServerSide.js");
|
|
25
25
|
const resolveRedirects_js_1 = require("./renderPage/resolveRedirects.js");
|
|
26
|
+
const resolveBase_js_1 = require("../shared/resolveBase.js");
|
|
26
27
|
const globalObject = (0, utils_js_1.getGlobalObject)('runtime/renderPage.ts', {
|
|
27
28
|
httpRequestsCount: 0
|
|
28
29
|
});
|
|
@@ -342,6 +343,7 @@ function assertIsNotViteRequest(urlPathname, urlOriginal) {
|
|
|
342
343
|
(0, utils_js_1.assertUsage)(false, `${picocolors_1.default.code('renderPage(pageContextInit)')} called with ${picocolors_1.default.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which is unexpected because the URL ${picocolors_1.default.bold(urlOriginal)} should have already been handled by the development middleware: make sure the ${picocolors_1.default.cyan('createDevMiddleware()')} middleware is executed *before* the ${picocolors_1.default.cyan('renderPage()')} middleware, see ${picocolors_1.default.underline('https://vike.dev/renderPage')}`);
|
|
343
344
|
}
|
|
344
345
|
async function normalizeUrl(pageContextInit, globalContext, httpRequestId) {
|
|
346
|
+
const { baseServer } = (0, resolveBase_js_1.resolveBaseRuntime)(globalContext);
|
|
345
347
|
const { trailingSlash, disableUrlNormalization } = globalContext.config;
|
|
346
348
|
if (disableUrlNormalization)
|
|
347
349
|
return null;
|
|
@@ -349,7 +351,7 @@ async function normalizeUrl(pageContextInit, globalContext, httpRequestId) {
|
|
|
349
351
|
const { isPageContextRequest } = (0, handlePageContextRequestUrl_js_1.handlePageContextRequestUrl)(urlOriginal);
|
|
350
352
|
if (isPageContextRequest)
|
|
351
353
|
return null;
|
|
352
|
-
const urlNormalized = (0, utils_js_1.normalizeUrlPathname)(urlOriginal, trailingSlash ?? false,
|
|
354
|
+
const urlNormalized = (0, utils_js_1.normalizeUrlPathname)(urlOriginal, trailingSlash ?? false, baseServer);
|
|
353
355
|
if (!urlNormalized)
|
|
354
356
|
return null;
|
|
355
357
|
(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');
|
|
@@ -359,7 +361,8 @@ async function normalizeUrl(pageContextInit, globalContext, httpRequestId) {
|
|
|
359
361
|
return pageContextHttpResponse;
|
|
360
362
|
}
|
|
361
363
|
async function getPermanentRedirect(pageContextInit, globalContext, httpRequestId) {
|
|
362
|
-
const
|
|
364
|
+
const { baseServer } = (0, resolveBase_js_1.resolveBaseRuntime)(globalContext);
|
|
365
|
+
const urlWithoutBase = (0, utils_js_1.removeBaseServer)(pageContextInit.urlOriginal, baseServer);
|
|
363
366
|
let origin = null;
|
|
364
367
|
let urlTargetExternal = null;
|
|
365
368
|
let urlTarget = (0, utils_js_1.modifyUrlPathname)(urlWithoutBase, (urlPathname) => {
|
|
@@ -390,8 +393,9 @@ async function getPermanentRedirect(pageContextInit, globalContext, httpRequestI
|
|
|
390
393
|
}
|
|
391
394
|
if (normalize(urlTarget) === normalize(urlWithoutBase))
|
|
392
395
|
return null;
|
|
396
|
+
const { baseServer } = (0, resolveBase_js_1.resolveBaseRuntime)(globalContext);
|
|
393
397
|
if (!originChanged)
|
|
394
|
-
urlTarget = (0, utils_js_1.prependBase)(urlTarget,
|
|
398
|
+
urlTarget = (0, utils_js_1.prependBase)(urlTarget, baseServer);
|
|
395
399
|
(0, utils_js_1.assert)(urlTarget !== pageContextInit.urlOriginal);
|
|
396
400
|
}
|
|
397
401
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`Permanent redirection defined by config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
|
|
@@ -455,7 +459,7 @@ pageContextNominalPageInit, httpRequestId, pageContextErrorPageInit, globalConte
|
|
|
455
459
|
return { pageContextAbort };
|
|
456
460
|
}
|
|
457
461
|
async function assertBaseUrl(pageContextInit, globalContext) {
|
|
458
|
-
const { baseServer } = globalContext;
|
|
462
|
+
const { baseServer } = (0, resolveBase_js_1.resolveBaseRuntime)(globalContext);
|
|
459
463
|
const { urlOriginal } = pageContextInit;
|
|
460
464
|
const { urlWithoutPageContextRequestSuffix } = (0, handlePageContextRequestUrl_js_1.handlePageContextRequestUrl)(urlOriginal);
|
|
461
465
|
const { hasBaseServer } = (0, utils_js_1.parseUrl)(urlWithoutPageContextRequestSuffix, baseServer);
|
|
@@ -4,8 +4,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.resolveBase = resolveBase;
|
|
7
|
+
exports.resolveBaseRuntime = resolveBaseRuntime;
|
|
8
|
+
exports.resolveBaseFromResolvedConfig = resolveBaseFromResolvedConfig;
|
|
7
9
|
const utils_js_1 = require("./utils.js");
|
|
8
10
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
11
|
+
function resolveBaseFromResolvedConfig(baseServer, baseAssets, config) {
|
|
12
|
+
let baseViteOriginal = config._baseViteOriginal;
|
|
13
|
+
(0, utils_js_1.assert)(baseViteOriginal === null || typeof baseViteOriginal == 'string');
|
|
14
|
+
return resolveBase(baseViteOriginal, baseServer, baseAssets);
|
|
15
|
+
}
|
|
16
|
+
function resolveBaseRuntime(globalContext) {
|
|
17
|
+
const baseViteOriginal = globalContext.viteConfigRuntime._baseViteOriginal;
|
|
18
|
+
const baseServerUnresolved = globalContext.config.baseServer ?? null;
|
|
19
|
+
const baseAssetsUnresolved = globalContext.config.baseAssets ?? null;
|
|
20
|
+
return resolveBase(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved);
|
|
21
|
+
}
|
|
9
22
|
function resolveBase(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved) {
|
|
10
23
|
if (baseViteOriginal === '/__UNSET__')
|
|
11
24
|
baseViteOriginal = null;
|
|
@@ -10,7 +10,7 @@ const getConfigDefinedAt_js_1 = require("../page-configs/getConfigDefinedAt.js")
|
|
|
10
10
|
const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
|
|
11
11
|
const getHook_js_1 = require("../hooks/getHook.js");
|
|
12
12
|
async function loadPageRoutes(
|
|
13
|
-
// Remove all arguments and use
|
|
13
|
+
// Remove all arguments and use GlobalContext instead?
|
|
14
14
|
pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds) {
|
|
15
15
|
// TODO/next-major: remove & make this function sync
|
|
16
16
|
await Promise.all(pageFilesAll.filter((p) => p.fileType === '.page.route').map((p) => p.loadFile?.()));
|
|
@@ -27,7 +27,7 @@ function assertSingleInstance() {
|
|
|
27
27
|
const versions = (0, unique_js_1.unique)(globalObject.instances);
|
|
28
28
|
assertUsage(versions.length <= 1,
|
|
29
29
|
// DO *NOT* patch vike to remove this error: because of multiple conflicting versions, you *will* eventually encounter insidious issues that hard to debug and potentially a security hazard, see for example https://github.com/vikejs/vike/issues/1108
|
|
30
|
-
`vike@${picocolors_1.default.bold(versions[0])} and vike@${picocolors_1.default.bold(versions[1])} loaded but
|
|
30
|
+
`vike@${picocolors_1.default.bold(versions[0])} and vike@${picocolors_1.default.bold(versions[1])} loaded but only one version should be loaded`);
|
|
31
31
|
}
|
|
32
32
|
if (globalObject.checkSingleInstance && globalObject.instances.length > 1) {
|
|
33
33
|
/*/ Not sure whether circular dependency can cause problems? In principle not since client-side code is ESM.
|
|
@@ -488,7 +488,7 @@ async function renderPageClientSide(renderArgs) {
|
|
|
488
488
|
}
|
|
489
489
|
}
|
|
490
490
|
// For Vike tests (but also potentially for Vike users)
|
|
491
|
-
//
|
|
491
|
+
// TODO/now add comment linking to usage example
|
|
492
492
|
function stampFinished(urlOriginal) {
|
|
493
493
|
window._vike ?? (window._vike = {});
|
|
494
494
|
window._vike.fullyRenderedUrl = urlOriginal;
|
|
@@ -4,10 +4,7 @@ export { plugin as ssr };
|
|
|
4
4
|
export type { VikeVitePluginOptions as UserConfig };
|
|
5
5
|
export type { VikeVitePluginOptions };
|
|
6
6
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
7
|
-
|
|
8
|
-
name: string;
|
|
9
|
-
};
|
|
10
|
-
declare function plugin(vikeVitePluginOptions?: VikeVitePluginOptions): PluginInterop[];
|
|
7
|
+
declare function plugin(vikeVitePluginOptions?: VikeVitePluginOptions): any;
|
|
11
8
|
/** @deprecated Define Vike settings in +config.js instead of vite.config.js */
|
|
12
9
|
type VikeVitePluginOptions = {
|
|
13
10
|
/** @deprecated Define Vike settings in +config.js instead of vite.config.js */
|
|
@@ -29,7 +29,7 @@ import { workaroundVite6HmrRegression } from './plugins/workaroundVite6HmrRegres
|
|
|
29
29
|
import { buildApp } from './plugins/buildApp.js';
|
|
30
30
|
// We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
|
|
31
31
|
setResolveClientEntriesDev(resolveClientEntriesDev);
|
|
32
|
-
// Return
|
|
32
|
+
// Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
|
|
33
33
|
function plugin(vikeVitePluginOptions = {}) {
|
|
34
34
|
const plugins = [
|
|
35
35
|
...commonConfig(vikeVitePluginOptions),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { baseUrls };
|
|
2
|
-
import { resolveBase } from '../../shared/resolveBase.js';
|
|
2
|
+
import { resolveBase, resolveBaseFromResolvedConfig } from '../../shared/resolveBase.js';
|
|
3
3
|
import { assert } from '../utils.js';
|
|
4
4
|
import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
|
|
5
5
|
function baseUrls() {
|
|
@@ -38,8 +38,3 @@ function baseUrls() {
|
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
-
function resolveBaseFromResolvedConfig(baseServer, baseAssets, config) {
|
|
42
|
-
let baseViteOriginal = config._baseViteOriginal;
|
|
43
|
-
assert(baseViteOriginal === null || typeof baseViteOriginal == 'string');
|
|
44
|
-
return resolveBase(baseViteOriginal, baseServer, baseAssets);
|
|
45
|
-
}
|
|
@@ -16,25 +16,24 @@ export { assertBuildInfo };
|
|
|
16
16
|
export { getViteConfigRuntime };
|
|
17
17
|
export { updateUserFiles };
|
|
18
18
|
export type { BuildInfo };
|
|
19
|
-
export type {
|
|
19
|
+
export type { GlobalContext };
|
|
20
20
|
export type { GlobalContextPublic };
|
|
21
21
|
import type { ViteManifest } from '../shared/ViteManifest.js';
|
|
22
22
|
import type { ResolvedConfig, ViteDevServer } from 'vite';
|
|
23
23
|
import type { ConfigUserFriendly, PageConfigsUserFriendly } from '../../shared/page-configs/getPageConfigUserFriendly.js';
|
|
24
24
|
import type { ConfigVitePluginServerEntry } from '@brillout/vite-plugin-server-entry/plugin';
|
|
25
|
-
|
|
26
|
-
type GlobalContextPublic = Pick<GlobalContext, 'assetsManifest' | 'config' | 'viteConfig' | 'pages' | 'baseAssets' | 'baseServer'>;
|
|
25
|
+
type GlobalContextPublic = Pick<GlobalContext, 'assetsManifest' | 'config' | 'viteConfig' | 'pages'>;
|
|
27
26
|
type PageRuntimeInfo = Awaited<ReturnType<typeof getUserFiles>>;
|
|
28
|
-
type
|
|
27
|
+
type GlobalContext = GlobalContextWithoutPublicCopy & {
|
|
29
28
|
globalContext_public: GlobalContextPublic;
|
|
30
29
|
};
|
|
31
|
-
type
|
|
30
|
+
type GlobalContextWithoutPublicCopy = {
|
|
32
31
|
viteConfigRuntime: {
|
|
33
32
|
_baseViteOriginal: null | string;
|
|
34
33
|
};
|
|
35
34
|
config: ConfigUserFriendly['config'];
|
|
36
35
|
pages: PageConfigsUserFriendly;
|
|
37
|
-
} &
|
|
36
|
+
} & PageRuntimeInfo & ({
|
|
38
37
|
isProduction: false;
|
|
39
38
|
isPrerendering: false;
|
|
40
39
|
viteConfig: ResolvedConfig;
|
|
@@ -52,7 +51,7 @@ type GlobalContext = {
|
|
|
52
51
|
usesClientRouter: boolean;
|
|
53
52
|
viteConfig: ResolvedConfig;
|
|
54
53
|
})));
|
|
55
|
-
declare function getGlobalContextInternal(): Promise<
|
|
54
|
+
declare function getGlobalContextInternal(): Promise<GlobalContext>;
|
|
56
55
|
/** @experimental https://vike.dev/getGlobalContext */
|
|
57
56
|
declare function getGlobalContextSync(): GlobalContextPublic;
|
|
58
57
|
/** @experimental https://vike.dev/getGlobalContext */
|
|
@@ -18,7 +18,7 @@ export { assertBuildInfo };
|
|
|
18
18
|
export { getViteConfigRuntime };
|
|
19
19
|
export { updateUserFiles };
|
|
20
20
|
// The core logic revolves around:
|
|
21
|
-
// - globalObject.userFiles which is the main requirement for
|
|
21
|
+
// - globalObject.userFiles which is the main requirement for assembleGlobalContext()
|
|
22
22
|
// - In production: globalObject.buildEntry which is the production entry set by @brillout/vite-plugin-server-entry
|
|
23
23
|
// - loadBuildEntry() sets globalObject.buildEntry and then sets globalObject.userFiles
|
|
24
24
|
// - With vike-server it's set at server start: @brillout/vite-plugin-server-entry injects `import './entry.mjs'` (the production entry generated by @brillout/vite-plugin-server-entry) as first line of code of dist/server/index.mjs while dist/server/entry.mjs calls setGlobalContext_buildEntry()
|
|
@@ -32,7 +32,6 @@ import pc from '@brillout/picocolors';
|
|
|
32
32
|
import { loadPageRoutes } from '../../shared/route/loadPageRoutes.js';
|
|
33
33
|
import { assertV1Design } from '../shared/assertV1Design.js';
|
|
34
34
|
import { getPageConfigsRuntime } from '../../shared/getPageConfigsRuntime.js';
|
|
35
|
-
import { resolveBase } from '../shared/resolveBase.js';
|
|
36
35
|
const debug = createDebugger('vike:globalContext');
|
|
37
36
|
const globalObject = getGlobalObject('globalContext.ts', getInitialGlobalContext());
|
|
38
37
|
async function getGlobalContextInternal() {
|
|
@@ -80,9 +79,7 @@ function makePublic(globalContext) {
|
|
|
80
79
|
'assetsManifest',
|
|
81
80
|
'config',
|
|
82
81
|
'viteConfig',
|
|
83
|
-
'pages'
|
|
84
|
-
'baseServer',
|
|
85
|
-
'baseAssets'
|
|
82
|
+
'pages'
|
|
86
83
|
]);
|
|
87
84
|
return globalContextPublic;
|
|
88
85
|
}
|
|
@@ -187,7 +184,7 @@ function setIsProduction(isProduction) {
|
|
|
187
184
|
globalObject.isProduction = isProduction;
|
|
188
185
|
}
|
|
189
186
|
function defineGlobalContext() {
|
|
190
|
-
const globalContext =
|
|
187
|
+
const globalContext = assembleGlobalContext();
|
|
191
188
|
assertIsDefined(globalContext);
|
|
192
189
|
const globalContext_public = makePublic(globalContext);
|
|
193
190
|
objectAssign(globalContext, { globalContext_public });
|
|
@@ -196,7 +193,7 @@ function defineGlobalContext() {
|
|
|
196
193
|
assertGlobalContextIsDefined();
|
|
197
194
|
onSetupRuntime();
|
|
198
195
|
}
|
|
199
|
-
function
|
|
196
|
+
function assembleGlobalContext() {
|
|
200
197
|
const { viteDevServer, viteConfig, isPrerendering, isProduction, userFiles } = globalObject;
|
|
201
198
|
assert(typeof isProduction === 'boolean');
|
|
202
199
|
let globalContext;
|
|
@@ -215,8 +212,7 @@ function resolveGlobalContext() {
|
|
|
215
212
|
viteDevServer,
|
|
216
213
|
viteConfig,
|
|
217
214
|
...userFiles,
|
|
218
|
-
viteConfigRuntime
|
|
219
|
-
...resolveBaseRuntime(viteConfigRuntime, userFiles.config)
|
|
215
|
+
viteConfigRuntime
|
|
220
216
|
};
|
|
221
217
|
}
|
|
222
218
|
else {
|
|
@@ -233,8 +229,7 @@ function resolveGlobalContext() {
|
|
|
233
229
|
...userFiles,
|
|
234
230
|
viteDevServer: null,
|
|
235
231
|
viteConfigRuntime: buildInfo.viteConfigRuntime,
|
|
236
|
-
usesClientRouter: buildInfo.usesClientRouter
|
|
237
|
-
...resolveBaseRuntime(buildInfo.viteConfigRuntime, userFiles.config)
|
|
232
|
+
usesClientRouter: buildInfo.usesClientRouter
|
|
238
233
|
};
|
|
239
234
|
if (isPrerendering) {
|
|
240
235
|
assert(viteConfig);
|
|
@@ -403,9 +398,3 @@ function getInitialGlobalContext() {
|
|
|
403
398
|
viteDevServerPromiseResolve
|
|
404
399
|
};
|
|
405
400
|
}
|
|
406
|
-
function resolveBaseRuntime(viteConfigRuntime, config) {
|
|
407
|
-
const baseViteOriginal = viteConfigRuntime._baseViteOriginal;
|
|
408
|
-
const baseServerUnresolved = config.baseServer ?? null;
|
|
409
|
-
const baseAssetsUnresolved = config.baseAssets ?? null;
|
|
410
|
-
return resolveBase(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved);
|
|
411
|
-
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getViteDevScript };
|
|
2
|
-
import type {
|
|
2
|
+
import type { GlobalContext } from '../../globalContext.js';
|
|
3
3
|
declare function getViteDevScript(pageContext: {
|
|
4
|
-
_globalContext:
|
|
4
|
+
_globalContext: GlobalContext;
|
|
5
5
|
}): Promise<string>;
|
|
@@ -8,7 +8,7 @@ import { type PreloadFilter } from './injectAssets/getHtmlTags.js';
|
|
|
8
8
|
import type { StreamFromReactStreamingPackage } from './stream/react-streaming.js';
|
|
9
9
|
import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
10
10
|
import type { PageContextSerialization } from './serializePageContextClientSide.js';
|
|
11
|
-
import type {
|
|
11
|
+
import type { GlobalContext } from '../globalContext.js';
|
|
12
12
|
type PageContextInjectAssets = {
|
|
13
13
|
urlPathname: string;
|
|
14
14
|
__getPageAssets: () => Promise<PageAsset[]>;
|
|
@@ -22,7 +22,7 @@ type PageContextInjectAssets = {
|
|
|
22
22
|
_baseServer: string;
|
|
23
23
|
_pageConfigs: PageConfigRuntime[];
|
|
24
24
|
is404: null | boolean;
|
|
25
|
-
_globalContext:
|
|
25
|
+
_globalContext: GlobalContext;
|
|
26
26
|
} & PageContextSerialization;
|
|
27
27
|
declare function injectHtmlTagsToString(htmlParts: HtmlPart[], pageContext: PageContextInjectAssets & {
|
|
28
28
|
_isStream: false;
|
|
@@ -2,5 +2,5 @@ export { analyzePage };
|
|
|
2
2
|
import type { PageFile } from '../../../shared/getPageFiles/getPageFileObject.js';
|
|
3
3
|
import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
4
4
|
import { type AnalysisResult } from '../../../shared/getPageFiles/analyzePageClientSide.js';
|
|
5
|
-
import type {
|
|
6
|
-
declare function analyzePage(pageFilesAll: PageFile[], pageConfig: null | PageConfigRuntime, pageId: string, globalContext:
|
|
5
|
+
import type { GlobalContext } from '../globalContext.js';
|
|
6
|
+
declare function analyzePage(pageFilesAll: PageFile[], pageConfig: null | PageConfigRuntime, pageId: string, globalContext: GlobalContext): Promise<AnalysisResult>;
|
|
@@ -5,7 +5,7 @@ export type { GetPageAssets };
|
|
|
5
5
|
export type { PageContextGetPageAssets };
|
|
6
6
|
import { type MediaType } from './inferMediaType.js';
|
|
7
7
|
import type { ClientDependency } from '../../../shared/getPageFiles/analyzePageClientSide/ClientDependency.js';
|
|
8
|
-
import type {
|
|
8
|
+
import type { GlobalContext } from '../globalContext.js';
|
|
9
9
|
import type { ResolveClientEntriesDev } from '../../plugin/shared/resolveClientEntriesDev.js';
|
|
10
10
|
type PageAsset = {
|
|
11
11
|
src: string;
|
|
@@ -18,7 +18,7 @@ type PageContextGetPageAssets = {
|
|
|
18
18
|
_baseServer: string;
|
|
19
19
|
_baseAssets: string | null;
|
|
20
20
|
_includeAssetsImportedByServer: boolean;
|
|
21
|
-
_globalContext:
|
|
21
|
+
_globalContext: GlobalContext;
|
|
22
22
|
};
|
|
23
23
|
declare function getPageAssets(pageContext: PageContextGetPageAssets, clientDependencies: ClientDependency[], clientEntries: string[]): Promise<PageAsset[]>;
|
|
24
24
|
declare function setResolveClientEntriesDev(resolveClientEntriesDev: ResolveClientEntriesDev): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { handleErrorWithoutErrorPage };
|
|
2
|
-
import type {
|
|
2
|
+
import type { GlobalContext } from '../globalContext.js';
|
|
3
3
|
import type { PageContextAfterRender } from './renderPageAlreadyRouted.js';
|
|
4
4
|
import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
5
5
|
import type { PageFile } from '../../../shared/getPageFiles.js';
|
|
@@ -10,6 +10,6 @@ declare function handleErrorWithoutErrorPage<PageContext extends {
|
|
|
10
10
|
pageId: null;
|
|
11
11
|
_pageFilesAll: PageFile[];
|
|
12
12
|
_pageConfigs: PageConfigRuntime[];
|
|
13
|
-
_globalContext:
|
|
13
|
+
_globalContext: GlobalContext;
|
|
14
14
|
urlOriginal: string;
|
|
15
15
|
}>(pageContext: PageContext): Promise<PageContext & PageContextAfterRender>;
|
|
@@ -6,12 +6,12 @@ import { PromiseType } from '../utils.js';
|
|
|
6
6
|
import { PageContextGetPageAssets, type PageAsset } from './getPageAssets.js';
|
|
7
7
|
import { type PageContextDebugRouteMatches } from './debugPageFiles.js';
|
|
8
8
|
import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
9
|
-
import type {
|
|
9
|
+
import type { GlobalContext } from '../globalContext.js';
|
|
10
10
|
type PageContext_loadUserFilesServerSide = PageContextGetPageAssets & PageContextDebugRouteMatches & {
|
|
11
11
|
urlOriginal: string;
|
|
12
12
|
_pageFilesAll: PageFile[];
|
|
13
13
|
_pageConfigs: PageConfigRuntime[];
|
|
14
|
-
_globalContext:
|
|
14
|
+
_globalContext: GlobalContext;
|
|
15
15
|
};
|
|
16
16
|
type PageFiles = PromiseType<ReturnType<typeof loadUserFilesServerSide>>;
|
|
17
17
|
declare function loadUserFilesServerSide(pageContext: {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export { log404 };
|
|
2
2
|
export { getRoutesInfo };
|
|
3
3
|
import type { PageRoutes } from '../../../../shared/route/index.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { GlobalContext } from '../../globalContext.js';
|
|
5
5
|
declare function log404(pageContext: {
|
|
6
6
|
urlPathname: string;
|
|
7
7
|
errorWhileRendering: null | Error;
|
|
8
8
|
isClientSideNavigation: boolean;
|
|
9
9
|
_pageRoutes: PageRoutes;
|
|
10
|
-
_globalContext:
|
|
10
|
+
_globalContext: GlobalContext;
|
|
11
11
|
}): Promise<void>;
|
|
12
12
|
declare function getRoutesInfo(pageRoutes: PageRoutes): string | null;
|
package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { PageContextUrlInternal } from '../../../shared/getPageContextUrlCompute
|
|
|
4
4
|
import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
5
5
|
import type { PageConfigUserFriendly } from '../../../shared/page-configs/getPageConfigUserFriendly.js';
|
|
6
6
|
import { PageContextBuiltInServerInternal } from '../../../shared/types.js';
|
|
7
|
-
import type {
|
|
7
|
+
import type { GlobalContext, GlobalContextPublic } from '../globalContext.js';
|
|
8
8
|
type PageContextForUserConsumptionServerSide = PageContextBuiltInServerInternal & PageConfigUserFriendly & {
|
|
9
9
|
urlOriginal: string;
|
|
10
10
|
/** @deprecated */
|
|
@@ -18,7 +18,7 @@ type PageContextForUserConsumptionServerSide = PageContextBuiltInServerInternal
|
|
|
18
18
|
is404: null | boolean;
|
|
19
19
|
isClientSideNavigation: boolean;
|
|
20
20
|
pageProps?: Record<string, unknown>;
|
|
21
|
-
_globalContext:
|
|
21
|
+
_globalContext: GlobalContext;
|
|
22
22
|
globalContext: GlobalContextPublic;
|
|
23
23
|
} & Record<string, unknown>;
|
|
24
24
|
declare function preparePageContextForUserConsumptionServerSide(pageContext: PageContextForUserConsumptionServerSide): void;
|
|
@@ -5,7 +5,7 @@ export { getPageContextInitEnhanced };
|
|
|
5
5
|
export type { PageContextAfterRender };
|
|
6
6
|
export type { PageContextInitEnhanced };
|
|
7
7
|
import { type PageContextUrlInternal } from '../../../shared/getPageContextUrlComputed.js';
|
|
8
|
-
import type {
|
|
8
|
+
import type { GlobalContext } from '../globalContext.js';
|
|
9
9
|
import { HttpResponse } from './createHttpResponse.js';
|
|
10
10
|
import { PageContext_loadUserFilesServerSide, type PageFiles } from './loadUserFilesServerSide.js';
|
|
11
11
|
type PageContextAfterRender = {
|
|
@@ -46,7 +46,7 @@ declare function prerenderPage(pageContext: PageContextInitEnhanced & PageFiles
|
|
|
46
46
|
_allPageIds: string[];
|
|
47
47
|
_pageRoutes: import("../../../__internal/index.js").PageRoutes;
|
|
48
48
|
_onBeforeRouteHook: import("../../../shared/hooks/getHook.js").Hook | null;
|
|
49
|
-
_globalContext:
|
|
49
|
+
_globalContext: GlobalContext;
|
|
50
50
|
/** @experimental This is a beta feature https://vike.dev/getGlobalContext */
|
|
51
51
|
globalContext: import("../globalContext.js").GlobalContextPublic;
|
|
52
52
|
_pageContextInit: {
|
|
@@ -100,7 +100,7 @@ declare function prerenderPage(pageContext: PageContextInitEnhanced & PageFiles
|
|
|
100
100
|
_allPageIds: string[];
|
|
101
101
|
_pageRoutes: import("../../../__internal/index.js").PageRoutes;
|
|
102
102
|
_onBeforeRouteHook: import("../../../shared/hooks/getHook.js").Hook | null;
|
|
103
|
-
_globalContext:
|
|
103
|
+
_globalContext: GlobalContext;
|
|
104
104
|
/** @experimental This is a beta feature https://vike.dev/getGlobalContext */
|
|
105
105
|
globalContext: import("../globalContext.js").GlobalContextPublic;
|
|
106
106
|
_pageContextInit: {
|
|
@@ -137,7 +137,7 @@ declare function prerenderPage(pageContext: PageContextInitEnhanced & PageFiles
|
|
|
137
137
|
_urlHandler: null;
|
|
138
138
|
};
|
|
139
139
|
}>;
|
|
140
|
-
declare function prerender404Page(pageContextInit_: Record<string, unknown> | null, globalContext:
|
|
140
|
+
declare function prerender404Page(pageContextInit_: Record<string, unknown> | null, globalContext: GlobalContext): Promise<{
|
|
141
141
|
documentHtml: string;
|
|
142
142
|
pageContextSerialized: null;
|
|
143
143
|
pageContext: {
|
|
@@ -155,7 +155,7 @@ declare function prerender404Page(pageContextInit_: Record<string, unknown> | nu
|
|
|
155
155
|
_allPageIds: string[];
|
|
156
156
|
_pageRoutes: import("../../../__internal/index.js").PageRoutes;
|
|
157
157
|
_onBeforeRouteHook: import("../../../shared/hooks/getHook.js").Hook | null;
|
|
158
|
-
_globalContext:
|
|
158
|
+
_globalContext: GlobalContext;
|
|
159
159
|
/** @experimental This is a beta feature https://vike.dev/getGlobalContext */
|
|
160
160
|
globalContext: import("../globalContext.js").GlobalContextPublic;
|
|
161
161
|
_pageContextInit: {
|
|
@@ -209,7 +209,7 @@ declare function prerender404Page(pageContextInit_: Record<string, unknown> | nu
|
|
|
209
209
|
_allPageIds: string[];
|
|
210
210
|
_pageRoutes: import("../../../__internal/index.js").PageRoutes;
|
|
211
211
|
_onBeforeRouteHook: import("../../../shared/hooks/getHook.js").Hook | null;
|
|
212
|
-
_globalContext:
|
|
212
|
+
_globalContext: GlobalContext;
|
|
213
213
|
/** @experimental This is a beta feature https://vike.dev/getGlobalContext */
|
|
214
214
|
globalContext: import("../globalContext.js").GlobalContextPublic;
|
|
215
215
|
_pageContextInit: {
|
|
@@ -251,7 +251,7 @@ declare function getPageContextInitEnhanced(pageContextInit: {
|
|
|
251
251
|
urlOriginal: string;
|
|
252
252
|
headersOriginal?: unknown;
|
|
253
253
|
headers?: unknown;
|
|
254
|
-
}, globalContext:
|
|
254
|
+
}, globalContext: GlobalContext, { ssr: { urlRewrite, urlHandler, isClientSideNavigation } }?: {
|
|
255
255
|
ssr?: {
|
|
256
256
|
urlRewrite: null | string;
|
|
257
257
|
urlHandler: null | ((url: string) => string);
|
|
@@ -272,7 +272,7 @@ declare function getPageContextInitEnhanced(pageContextInit: {
|
|
|
272
272
|
_allPageIds: string[];
|
|
273
273
|
_pageRoutes: import("../../../__internal/index.js").PageRoutes;
|
|
274
274
|
_onBeforeRouteHook: import("../../../shared/hooks/getHook.js").Hook | null;
|
|
275
|
-
_globalContext:
|
|
275
|
+
_globalContext: GlobalContext;
|
|
276
276
|
/** @experimental This is a beta feature https://vike.dev/getGlobalContext */
|
|
277
277
|
globalContext: import("../globalContext.js").GlobalContextPublic;
|
|
278
278
|
_pageContextInit: {
|
|
@@ -17,6 +17,7 @@ import { preparePageContextForUserConsumptionServerSide } from './preparePageCon
|
|
|
17
17
|
import { executeGuardHook } from '../../../shared/route/executeGuardHook.js';
|
|
18
18
|
import pc from '@brillout/picocolors';
|
|
19
19
|
import { isServerSideError } from '../../../shared/misc/isServerSideError.js';
|
|
20
|
+
import { resolveBaseRuntime } from '../../shared/resolveBase.js';
|
|
20
21
|
async function renderPageAlreadyRouted(pageContext) {
|
|
21
22
|
// pageContext.pageId can either be the:
|
|
22
23
|
// - ID of the page matching the routing, or the
|
|
@@ -111,13 +112,14 @@ async function getPageContextInitEnhanced(pageContextInit, globalContext, { ssr:
|
|
|
111
112
|
isClientSideNavigation: false
|
|
112
113
|
} } = {}) {
|
|
113
114
|
assert(pageContextInit.urlOriginal);
|
|
115
|
+
const { baseServer, baseAssets } = resolveBaseRuntime(globalContext);
|
|
114
116
|
const pageContextInitEnhanced = {};
|
|
115
117
|
objectAssign(pageContextInitEnhanced, pageContextInit);
|
|
116
118
|
objectAssign(pageContextInitEnhanced, {
|
|
117
119
|
_objectCreatedByVike: true,
|
|
118
120
|
// The following is defined on `pageContext` because we can eventually make these non-global
|
|
119
|
-
_baseServer:
|
|
120
|
-
_baseAssets:
|
|
121
|
+
_baseServer: baseServer,
|
|
122
|
+
_baseAssets: baseAssets,
|
|
121
123
|
// TODO/now: add meta.default
|
|
122
124
|
_includeAssetsImportedByServer: globalContext.config.includeAssetsImportedByServer ?? true,
|
|
123
125
|
// TODO/soon: use GloablContext instead
|
|
@@ -18,6 +18,7 @@ import { getErrorPageId } from '../../shared/error-page.js';
|
|
|
18
18
|
import { handleErrorWithoutErrorPage } from './renderPage/handleErrorWithoutErrorPage.js';
|
|
19
19
|
import { loadUserFilesServerSide } from './renderPage/loadUserFilesServerSide.js';
|
|
20
20
|
import { resolveRedirects } from './renderPage/resolveRedirects.js';
|
|
21
|
+
import { resolveBaseRuntime } from '../shared/resolveBase.js';
|
|
21
22
|
const globalObject = getGlobalObject('runtime/renderPage.ts', {
|
|
22
23
|
httpRequestsCount: 0
|
|
23
24
|
});
|
|
@@ -336,6 +337,7 @@ function assertIsNotViteRequest(urlPathname, urlOriginal) {
|
|
|
336
337
|
assertUsage(false, `${pc.code('renderPage(pageContextInit)')} called with ${pc.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which is unexpected because the URL ${pc.bold(urlOriginal)} should have already been handled by the development middleware: make sure the ${pc.cyan('createDevMiddleware()')} middleware is executed *before* the ${pc.cyan('renderPage()')} middleware, see ${pc.underline('https://vike.dev/renderPage')}`);
|
|
337
338
|
}
|
|
338
339
|
async function normalizeUrl(pageContextInit, globalContext, httpRequestId) {
|
|
340
|
+
const { baseServer } = resolveBaseRuntime(globalContext);
|
|
339
341
|
const { trailingSlash, disableUrlNormalization } = globalContext.config;
|
|
340
342
|
if (disableUrlNormalization)
|
|
341
343
|
return null;
|
|
@@ -343,7 +345,7 @@ async function normalizeUrl(pageContextInit, globalContext, httpRequestId) {
|
|
|
343
345
|
const { isPageContextRequest } = handlePageContextRequestUrl(urlOriginal);
|
|
344
346
|
if (isPageContextRequest)
|
|
345
347
|
return null;
|
|
346
|
-
const urlNormalized = normalizeUrlPathname(urlOriginal, trailingSlash ?? false,
|
|
348
|
+
const urlNormalized = normalizeUrlPathname(urlOriginal, trailingSlash ?? false, baseServer);
|
|
347
349
|
if (!urlNormalized)
|
|
348
350
|
return null;
|
|
349
351
|
logRuntimeInfo?.(`URL normalized from ${pc.cyan(urlOriginal)} to ${pc.cyan(urlNormalized)} (https://vike.dev/url-normalization)`, httpRequestId, 'info');
|
|
@@ -353,7 +355,8 @@ async function normalizeUrl(pageContextInit, globalContext, httpRequestId) {
|
|
|
353
355
|
return pageContextHttpResponse;
|
|
354
356
|
}
|
|
355
357
|
async function getPermanentRedirect(pageContextInit, globalContext, httpRequestId) {
|
|
356
|
-
const
|
|
358
|
+
const { baseServer } = resolveBaseRuntime(globalContext);
|
|
359
|
+
const urlWithoutBase = removeBaseServer(pageContextInit.urlOriginal, baseServer);
|
|
357
360
|
let origin = null;
|
|
358
361
|
let urlTargetExternal = null;
|
|
359
362
|
let urlTarget = modifyUrlPathname(urlWithoutBase, (urlPathname) => {
|
|
@@ -384,8 +387,9 @@ async function getPermanentRedirect(pageContextInit, globalContext, httpRequestI
|
|
|
384
387
|
}
|
|
385
388
|
if (normalize(urlTarget) === normalize(urlWithoutBase))
|
|
386
389
|
return null;
|
|
390
|
+
const { baseServer } = resolveBaseRuntime(globalContext);
|
|
387
391
|
if (!originChanged)
|
|
388
|
-
urlTarget = prependBase(urlTarget,
|
|
392
|
+
urlTarget = prependBase(urlTarget, baseServer);
|
|
389
393
|
assert(urlTarget !== pageContextInit.urlOriginal);
|
|
390
394
|
}
|
|
391
395
|
logRuntimeInfo?.(`Permanent redirection defined by config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
|
|
@@ -449,7 +453,7 @@ pageContextNominalPageInit, httpRequestId, pageContextErrorPageInit, globalConte
|
|
|
449
453
|
return { pageContextAbort };
|
|
450
454
|
}
|
|
451
455
|
async function assertBaseUrl(pageContextInit, globalContext) {
|
|
452
|
-
const { baseServer } = globalContext;
|
|
456
|
+
const { baseServer } = resolveBaseRuntime(globalContext);
|
|
453
457
|
const { urlOriginal } = pageContextInit;
|
|
454
458
|
const { urlWithoutPageContextRequestSuffix } = handlePageContextRequestUrl(urlOriginal);
|
|
455
459
|
const { hasBaseServer } = parseUrl(urlWithoutPageContextRequestSuffix, baseServer);
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
export { resolveBase };
|
|
2
|
-
export
|
|
2
|
+
export { resolveBaseRuntime };
|
|
3
|
+
export { resolveBaseFromResolvedConfig };
|
|
4
|
+
import type { ResolvedConfig } from 'vite';
|
|
5
|
+
import type { GlobalContext } from '../runtime/globalContext.js';
|
|
6
|
+
declare function resolveBaseFromResolvedConfig(baseServer: string | null, baseAssets: string | null, config: ResolvedConfig): {
|
|
7
|
+
baseServer: string;
|
|
8
|
+
baseAssets: string;
|
|
9
|
+
};
|
|
3
10
|
type BaseUrlsResolved = {
|
|
4
11
|
baseServer: string;
|
|
5
12
|
baseAssets: string;
|
|
6
13
|
};
|
|
14
|
+
declare function resolveBaseRuntime(globalContext: GlobalContext): BaseUrlsResolved;
|
|
7
15
|
declare function resolveBase(baseViteOriginal: string | null, baseServerUnresolved: string | null, baseAssetsUnresolved: string | null): BaseUrlsResolved;
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
export { resolveBase };
|
|
2
|
+
export { resolveBaseRuntime };
|
|
3
|
+
export { resolveBaseFromResolvedConfig };
|
|
2
4
|
import { assert, assertUsage, isBaseServer, isBaseAssets } from './utils.js';
|
|
3
5
|
import pc from '@brillout/picocolors';
|
|
6
|
+
function resolveBaseFromResolvedConfig(baseServer, baseAssets, config) {
|
|
7
|
+
let baseViteOriginal = config._baseViteOriginal;
|
|
8
|
+
assert(baseViteOriginal === null || typeof baseViteOriginal == 'string');
|
|
9
|
+
return resolveBase(baseViteOriginal, baseServer, baseAssets);
|
|
10
|
+
}
|
|
11
|
+
function resolveBaseRuntime(globalContext) {
|
|
12
|
+
const baseViteOriginal = globalContext.viteConfigRuntime._baseViteOriginal;
|
|
13
|
+
const baseServerUnresolved = globalContext.config.baseServer ?? null;
|
|
14
|
+
const baseAssetsUnresolved = globalContext.config.baseAssets ?? null;
|
|
15
|
+
return resolveBase(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved);
|
|
16
|
+
}
|
|
4
17
|
function resolveBase(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved) {
|
|
5
18
|
if (baseViteOriginal === '/__UNSET__')
|
|
6
19
|
baseViteOriginal = null;
|
|
@@ -8,7 +8,7 @@ import { getDefinedAtString } from '../page-configs/getConfigDefinedAt.js';
|
|
|
8
8
|
import { warnDeprecatedAllowKey } from './resolveRouteFunction.js';
|
|
9
9
|
import { getHookFromPageConfigGlobal, getHookTimeoutDefault } from '../hooks/getHook.js';
|
|
10
10
|
async function loadPageRoutes(
|
|
11
|
-
// Remove all arguments and use
|
|
11
|
+
// Remove all arguments and use GlobalContext instead?
|
|
12
12
|
pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds) {
|
|
13
13
|
// TODO/next-major: remove & make this function sync
|
|
14
14
|
await Promise.all(pageFilesAll.filter((p) => p.fileType === '.page.route').map((p) => p.loadFile?.()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.222
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.222";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.222
|
|
2
|
+
export const PROJECT_VERSION = '0.4.222';
|
|
@@ -22,7 +22,7 @@ function assertSingleInstance() {
|
|
|
22
22
|
const versions = unique(globalObject.instances);
|
|
23
23
|
assertUsage(versions.length <= 1,
|
|
24
24
|
// DO *NOT* patch vike to remove this error: because of multiple conflicting versions, you *will* eventually encounter insidious issues that hard to debug and potentially a security hazard, see for example https://github.com/vikejs/vike/issues/1108
|
|
25
|
-
`vike@${pc.bold(versions[0])} and vike@${pc.bold(versions[1])} loaded but
|
|
25
|
+
`vike@${pc.bold(versions[0])} and vike@${pc.bold(versions[1])} loaded but only one version should be loaded`);
|
|
26
26
|
}
|
|
27
27
|
if (globalObject.checkSingleInstance && globalObject.instances.length > 1) {
|
|
28
28
|
/*/ Not sure whether circular dependency can cause problems? In principle not since client-side code is ESM.
|