vike 0.4.222-commit-ce4e16e → 0.4.222-commit-fab3841

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.
Files changed (56) hide show
  1. package/dist/cjs/client/shared/getPageContextProxyForUser.js +1 -1
  2. package/dist/cjs/node/api/prepareViteApiCall.js +1 -1
  3. package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +1 -1
  4. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -1
  5. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +5 -5
  6. package/dist/cjs/node/runtime/globalContext.js +1 -1
  7. package/dist/cjs/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +1 -1
  8. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +24 -0
  9. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +1 -1
  10. package/dist/cjs/node/runtime/renderPage/handlePageContextRequestUrl.js +1 -1
  11. package/dist/cjs/node/runtime/renderPage/isNewError.js +1 -1
  12. package/dist/cjs/node/runtime/renderPage/isVikeConfigInvalid.js +10 -0
  13. package/dist/cjs/node/runtime/renderPage.js +44 -30
  14. package/dist/cjs/shared/getPageContextRequestUrl.js +1 -1
  15. package/dist/cjs/shared/getPageContextUrlComputed.js +10 -7
  16. package/dist/cjs/shared/hooks/getHook.js +1 -1
  17. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  18. package/dist/cjs/utils/assertSetup.js +1 -1
  19. package/dist/cjs/utils/assertSingleInstance.js +1 -1
  20. package/dist/cjs/utils/getGlobalObject.js +2 -6
  21. package/dist/esm/client/client-routing-runtime/getPageContextCurrent.js +1 -1
  22. package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +1 -1
  23. package/dist/esm/client/client-routing-runtime/history.js +1 -1
  24. package/dist/esm/client/client-routing-runtime/prefetch.js +1 -1
  25. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +1 -1
  26. package/dist/esm/client/client-routing-runtime/scrollRestoration.js +1 -1
  27. package/dist/esm/client/shared/getPageContextProxyForUser.js +1 -1
  28. package/dist/esm/node/api/prepareViteApiCall.js +1 -1
  29. package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +1 -1
  30. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -1
  31. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +5 -5
  32. package/dist/esm/node/runtime/globalContext.js +1 -1
  33. package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +1 -1
  34. package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +2 -0
  35. package/dist/esm/node/runtime/renderPage/createHttpResponse.js +24 -0
  36. package/dist/esm/node/runtime/renderPage/getPageAssets.js +1 -1
  37. package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.js +1 -1
  38. package/dist/esm/node/runtime/renderPage/isNewError.js +1 -1
  39. package/dist/esm/node/runtime/renderPage/isVikeConfigInvalid.d.ts +6 -0
  40. package/dist/esm/node/runtime/renderPage/isVikeConfigInvalid.js +8 -0
  41. package/dist/esm/node/runtime/renderPage.js +45 -31
  42. package/dist/esm/shared/getPageContextRequestUrl.js +1 -1
  43. package/dist/esm/shared/getPageContextUrlComputed.js +10 -7
  44. package/dist/esm/shared/hooks/getHook.js +1 -1
  45. package/dist/esm/shared/types.d.ts +6 -0
  46. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  47. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  48. package/dist/esm/utils/assertSetup.js +1 -1
  49. package/dist/esm/utils/assertSingleInstance.js +1 -1
  50. package/dist/esm/utils/getGlobalObject.d.ts +3 -2
  51. package/dist/esm/utils/getGlobalObject.js +2 -6
  52. package/dist/esm/utils/projectInfo.d.ts +1 -1
  53. package/package.json +1 -1
  54. package/dist/cjs/node/runtime/renderPage/isConfigInvalid.js +0 -10
  55. package/dist/esm/node/runtime/renderPage/isConfigInvalid.d.ts +0 -6
  56. package/dist/esm/node/runtime/renderPage/isConfigInvalid.js +0 -8
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPageContextProxyForUser = getPageContextProxyForUser;
4
4
  const utils_js_1 = require("../server-routing-runtime/utils.js");
5
5
  const notSerializable_js_1 = require("../../shared/notSerializable.js");
6
- const globalObject = (0, utils_js_1.getGlobalObject)('getPageContextProxyForUser.ts', {});
6
+ const globalObject = (0, utils_js_1.getGlobalObject)('shared/getPageContextProxyForUser.ts', {});
7
7
  /**
8
8
  * Throw error when pageContext value isn't:
9
9
  * - serializable, or
@@ -48,7 +48,7 @@ const path_1 = __importDefault(require("path"));
48
48
  const utils_js_1 = require("./utils.js");
49
49
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
50
50
  const globalContext_js_1 = require("../runtime/globalContext.js");
51
- const globalObject = (0, utils_js_1.getGlobalObject)('prepareViteApiCall.ts', {});
51
+ const globalObject = (0, utils_js_1.getGlobalObject)('api/prepareViteApiCall.ts', {});
52
52
  async function prepareViteApiCall(viteConfigFromOptions, operation) {
53
53
  clear();
54
54
  (0, context_js_1.setContextApiOperation)(operation);
@@ -11,7 +11,7 @@ const viteIsSSR_js_1 = require("../shared/viteIsSSR.js");
11
11
  const extractExportNamesRE = /(\?|&)extractExportNames(?:&|$)/;
12
12
  exports.extractExportNamesRE = extractExportNamesRE;
13
13
  const debug = (0, utils_js_1.createDebugger)('vike:extractExportNames');
14
- const globalObject = (0, utils_js_1.getGlobalObject)('extractExportNamesPlugin.ts', {});
14
+ const globalObject = (0, utils_js_1.getGlobalObject)('plugins/extractExportNamesPlugin.ts', {});
15
15
  function extractExportNamesPlugin() {
16
16
  let isDev = false;
17
17
  return {
@@ -16,7 +16,7 @@ const getEnvVarObject_js_1 = require("../../../../shared/getEnvVarObject.js");
16
16
  const execA = (0, util_1.promisify)(child_process_1.exec);
17
17
  const debug = (0, utils_js_1.createDebugger)('vike:crawl');
18
18
  (0, utils_js_1.assertIsNotProductionRuntime)();
19
- (0, utils_js_1.assertIsSingleModuleInstance)('crawlPlusFiles.ts');
19
+ (0, utils_js_1.assertIsSingleModuleInstance)('getVikeConfig/crawlPlusFiles.ts');
20
20
  let gitIsNotUsable = false;
21
21
  async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem) {
22
22
  (0, utils_js_1.assertPosixPath)(userRootDir);
@@ -13,7 +13,7 @@ exports.getConfigDefinitionOptional = getConfigDefinitionOptional;
13
13
  const utils_js_1 = require("../../../utils.js");
14
14
  const configDefinitionsBuiltIn_js_1 = require("./getVikeConfig/configDefinitionsBuiltIn.js");
15
15
  const filesystemRouting_js_1 = require("./getVikeConfig/filesystemRouting.js");
16
- const isConfigInvalid_js_1 = require("../../../../runtime/renderPage/isConfigInvalid.js");
16
+ const isVikeConfigInvalid_js_1 = require("../../../../runtime/renderPage/isVikeConfigInvalid.js");
17
17
  const globalContext_js_1 = require("../../../../runtime/globalContext.js");
18
18
  const loggerNotProd_js_1 = require("../../../shared/loggerNotProd.js");
19
19
  const removeSuperfluousViteLog_js_1 = require("../../../shared/loggerVite/removeSuperfluousViteLog.js");
@@ -43,7 +43,7 @@ function reloadVikeConfig(config) {
43
43
  handleReloadSideEffects();
44
44
  }
45
45
  async function handleReloadSideEffects() {
46
- wasConfigInvalid = !!isConfigInvalid_js_1.isConfigInvalid;
46
+ wasConfigInvalid = !!isVikeConfigInvalid_js_1.isVikeConfigInvalid;
47
47
  const vikeConfigPromisePrevious = vikeConfigPromise;
48
48
  try {
49
49
  await vikeConfigPromise;
@@ -58,7 +58,7 @@ async function handleReloadSideEffects() {
58
58
  // Let the next handleReloadSideEffects() call handle side effects
59
59
  return;
60
60
  }
61
- if (!isConfigInvalid_js_1.isConfigInvalid) {
61
+ if (!isVikeConfigInvalid_js_1.isVikeConfigInvalid) {
62
62
  if (wasConfigInvalid) {
63
63
  wasConfigInvalid = false;
64
64
  (0, loggerNotProd_js_1.logConfigErrorRecover)();
@@ -111,13 +111,13 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, vikeVitePlug
111
111
  if (!hasError) {
112
112
  (0, utils_js_1.assert)(ret);
113
113
  (0, utils_js_1.assert)(err === undefined);
114
- (0, isConfigInvalid_js_1.isConfigInvalid_set)(false);
114
+ (0, isVikeConfigInvalid_js_1.isVikeConfigInvalid_set)(false);
115
115
  return ret;
116
116
  }
117
117
  else {
118
118
  (0, utils_js_1.assert)(ret === undefined);
119
119
  (0, utils_js_1.assert)(err);
120
- (0, isConfigInvalid_js_1.isConfigInvalid_set)({ err });
120
+ (0, isVikeConfigInvalid_js_1.isVikeConfigInvalid_set)({ err });
121
121
  if (!isDev) {
122
122
  (0, utils_js_1.assert)((0, globalContext_js_1.getViteDevServer)() === null);
123
123
  throw err;
@@ -37,7 +37,7 @@ const assertV1Design_js_1 = require("../shared/assertV1Design.js");
37
37
  const getPageConfigsRuntime_js_1 = require("../../shared/getPageConfigsRuntime.js");
38
38
  const resolveBase_js_1 = require("../shared/resolveBase.js");
39
39
  const debug = (0, utils_js_1.createDebugger)('vike:globalContext');
40
- const globalObject = (0, utils_js_1.getGlobalObject)('globalContext.ts', getInitialGlobalContext());
40
+ const globalObject = (0, utils_js_1.getGlobalObject)('runtime/globalContext.ts', getInitialGlobalContext());
41
41
  async function getGlobalContextInternal() {
42
42
  // getGlobalContextInternal() should always be called after initGlobalContext()
43
43
  (0, utils_js_1.assert)(globalObject.isInitialized);
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.assertNoInfiniteHttpRedirect = assertNoInfiniteHttpRedirect;
7
7
  const utils_js_1 = require("../../utils.js");
8
8
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
9
- const globalObject = (0, utils_js_1.getGlobalObject)('assertNoInfiniteHttpRedirect.ts', {
9
+ const globalObject = (0, utils_js_1.getGlobalObject)('createHttpResponse/assertNoInfiniteHttpRedirect.ts', {
10
10
  redirectGraph: {}
11
11
  });
12
12
  function assertNoInfiniteHttpRedirect(urlRedirectTarget, urlLogical) {
@@ -5,6 +5,7 @@ exports.createHttpResponsePageContextJson = createHttpResponsePageContextJson;
5
5
  exports.createHttpResponseError = createHttpResponseError;
6
6
  exports.createHttpResponseRedirect = createHttpResponseRedirect;
7
7
  exports.createHttpResponseFavicon404 = createHttpResponseFavicon404;
8
+ exports.createHttpResponseBaseIsMissing = createHttpResponseBaseIsMissing;
8
9
  const utils_js_1 = require("../utils.js");
9
10
  const error_page_js_1 = require("../../../shared/error-page.js");
10
11
  const getHttpResponseBody_js_1 = require("./getHttpResponseBody.js");
@@ -40,6 +41,29 @@ function createHttpResponseFavicon404() {
40
41
  const httpResponse = createHttpResponse(404, 'text/html;charset=utf-8', [], "<p>No favicon.ico found.</p><script>console.log('This HTTP response was generated by Vike.')</script>");
41
42
  return httpResponse;
42
43
  }
44
+ function createHttpResponseBaseIsMissing(urlOriginal, baseServer) {
45
+ const httpResponse = createHttpResponse(
46
+ // We use the error code `500` to signal a failing state because this HTTP response should never be used, see https://vike.dev/base-url#setup
47
+ // In other words: this HTTP response is expected to be generated but isn't expected to be actually used.
48
+ 500, 'text/html;charset=utf-8', [], `
49
+ <h1>Error: Base URL is missing</h1>
50
+ <p>
51
+ <a href="https://vike.dev/renderPage"><code>renderPage(pageContextInit)</code></a> called with <code>pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}</code> which doesn't start with the Base URL <code>${baseServer}</code>.
52
+ </p>
53
+ <p>
54
+ See <a href="https://vike.dev/base-url#setup">vike.dev/base-url#setup</a> for how to properly setup your server while using a Base URL.
55
+ </p>
56
+ <style>
57
+ code {
58
+ font-family: monospace;
59
+ background-color: #eaeaea;
60
+ padding: 3px 5px;
61
+ border-radius: 4px;
62
+ }
63
+ </style>
64
+ `);
65
+ return httpResponse;
66
+ }
43
67
  function createHttpResponseError(pageContext) {
44
68
  const reason = (() => {
45
69
  if (!pageContext) {
@@ -8,7 +8,7 @@ const retrieveAssetsProd_js_1 = require("./getPageAssets/retrieveAssetsProd.js")
8
8
  const inferMediaType_js_1 = require("./inferMediaType.js");
9
9
  const getManifestEntry_js_1 = require("./getPageAssets/getManifestEntry.js");
10
10
  const sortPageAssetsForEarlyHintsHeader_js_1 = require("./getPageAssets/sortPageAssetsForEarlyHintsHeader.js");
11
- const globalObject = (0, utils_js_1.getGlobalObject)('getPageAssets.ts', {
11
+ const globalObject = (0, utils_js_1.getGlobalObject)('renderPage/getPageAssets.ts', {
12
12
  resolveClientEntriesDev: null
13
13
  });
14
14
  async function getPageAssets(pageContext, clientDependencies, clientEntries) {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handlePageContextRequestUrl = handlePageContextRequestUrl;
4
4
  const getPageContextRequestUrl_js_1 = require("../../../shared/getPageContextRequestUrl.js");
5
5
  const utils_js_1 = require("../utils.js");
6
- // See shared/getPageContextRequestUrl.ts
6
+ // See also shared/getPageContextRequestUrl.ts
7
7
  function handlePageContextRequestUrl(url) {
8
8
  if (!hasSuffix(url)) {
9
9
  return { urlWithoutPageContextRequestSuffix: url, isPageContextRequest: false };
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isNewError = isNewError;
4
4
  exports.setAlreadyLogged = setAlreadyLogged;
5
5
  const utils_js_1 = require("../utils.js");
6
- const globalObject = (0, utils_js_1.getGlobalObject)('runtime/renderPage/isNewError.ts', {
6
+ const globalObject = (0, utils_js_1.getGlobalObject)('renderPage/isNewError.ts', {
7
7
  wasAlreadyLogged: new WeakSet()
8
8
  });
9
9
  function isNewError(errErrorPage, errNominalPage) {
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isVikeConfigInvalid_set = exports.isVikeConfigInvalid = void 0;
4
+ const utils_js_1 = require("../utils.js");
5
+ let isVikeConfigInvalid;
6
+ const isVikeConfigInvalid_set = (val) => {
7
+ (0, utils_js_1.assert)(val === false || val.err);
8
+ exports.isVikeConfigInvalid = isVikeConfigInvalid = val;
9
+ };
10
+ exports.isVikeConfigInvalid_set = isVikeConfigInvalid_set;
@@ -16,7 +16,7 @@ const loggerRuntime_js_1 = require("./renderPage/loggerRuntime.js");
16
16
  const isNewError_js_1 = require("./renderPage/isNewError.js");
17
17
  const assertArguments_js_1 = require("./renderPage/assertArguments.js");
18
18
  const index_js_2 = require("./renderPage/log404/index.js");
19
- const isConfigInvalid_js_1 = require("./renderPage/isConfigInvalid.js");
19
+ const isVikeConfigInvalid_js_1 = require("./renderPage/isVikeConfigInvalid.js");
20
20
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
21
21
  const serializePageContextClientSide_js_1 = require("./html/serializePageContextClientSide.js");
22
22
  const error_page_js_1 = require("../../shared/error-page.js");
@@ -30,12 +30,11 @@ const globalObject = (0, utils_js_1.getGlobalObject)('runtime/renderPage.ts', {
30
30
  async function renderPage(pageContextInit) {
31
31
  (0, assertArguments_js_1.assertArguments)(...arguments);
32
32
  (0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContextInit, 'urlOriginal', 'string')); // assertUsage() already implemented at assertArguments()
33
- (0, utils_js_1.onSetupRuntime)();
34
33
  assertIsUrl(pageContextInit.urlOriginal);
35
- const urlPathnameWithBase = (0, utils_js_1.parseUrl)(pageContextInit.urlOriginal, '/').pathname;
36
- assertIsNotViteRequest(urlPathnameWithBase, pageContextInit.urlOriginal);
37
- if (urlPathnameWithBase.endsWith('/favicon.ico'))
38
- return getPageContextHttpResponseFavicon404(pageContextInit);
34
+ (0, utils_js_1.onSetupRuntime)();
35
+ const pageContextInvalidRequest = renderInvalidRequest(pageContextInit);
36
+ if (pageContextInvalidRequest)
37
+ return pageContextInvalidRequest;
39
38
  const httpRequestId = getRequestId();
40
39
  const urlOriginalPretty = (0, utils_js_1.getUrlPretty)(pageContextInit.urlOriginal);
41
40
  logHttpRequest(urlOriginalPretty, httpRequestId);
@@ -55,15 +54,10 @@ function renderPage_addAsyncHookwrapper(wrapper) {
55
54
  }
56
55
  async function renderPageAndPrepare(pageContextInit, httpRequestId) {
57
56
  // Invalid config
58
- const handleInvalidConfig = (err) => {
59
- (0, loggerRuntime_js_1.logRuntimeInfo)?.(picocolors_1.default.bold(picocolors_1.default.red('Error while loading a Vike config file, see error above.')), httpRequestId, 'error');
60
- const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
61
- return pageContextWithError;
62
- };
63
- if (isConfigInvalid_js_1.isConfigInvalid) {
57
+ if (isVikeConfigInvalid_js_1.isVikeConfigInvalid) {
64
58
  if (1 < 2 // Make TS happy
65
59
  ) {
66
- return handleInvalidConfig(isConfigInvalid_js_1.isConfigInvalid.err);
60
+ return renderInvalidVikeConfig(isVikeConfigInvalid_js_1.isVikeConfigInvalid.err, pageContextInit, httpRequestId);
67
61
  }
68
62
  }
69
63
  // Prepare context
@@ -81,15 +75,19 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
81
75
  const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
82
76
  return pageContextWithError;
83
77
  }
84
- if (isConfigInvalid_js_1.isConfigInvalid) {
85
- return handleInvalidConfig(isConfigInvalid_js_1.isConfigInvalid.err);
78
+ if (isVikeConfigInvalid_js_1.isVikeConfigInvalid) {
79
+ return renderInvalidVikeConfig(isVikeConfigInvalid_js_1.isVikeConfigInvalid.err, pageContextInit, httpRequestId);
86
80
  }
87
81
  else {
88
- // From now on, globalContext contains all the configuration data; getVikeConfig() isn't called anymore for this request
82
+ // `globalContext` now contains the entire Vike config and getVikeConfig() isn't called anymore for this request.
89
83
  }
90
84
  const globalContext = await (0, globalContext_js_1.getGlobalContextInternal)();
91
85
  // Check Base URL
92
- await assertBaseUrl(pageContextInit, globalContext);
86
+ {
87
+ const pageContextHttpResponse = await checkBaseUrl(pageContextInit, globalContext);
88
+ if (pageContextHttpResponse)
89
+ return pageContextHttpResponse;
90
+ }
93
91
  // Normalize URL
94
92
  {
95
93
  const pageContextHttpResponse = await normalizeUrl(pageContextInit, globalContext, httpRequestId);
@@ -257,15 +255,6 @@ function getPageContextHttpResponseError(err, pageContextInit, pageContext) {
257
255
  });
258
256
  return pageContextWithError;
259
257
  }
260
- function getPageContextHttpResponseFavicon404(pageContextInit) {
261
- const pageContext = createPageContext(pageContextInit);
262
- const httpResponse = (0, createHttpResponse_js_1.createHttpResponseFavicon404)();
263
- (0, utils_js_1.objectAssign)(pageContext, {
264
- httpResponse
265
- });
266
- (0, utils_js_1.checkType)(pageContext);
267
- return pageContext;
268
- }
269
258
  function createPageContext(pageContextInit) {
270
259
  const pageContext = {
271
260
  _isPageContextObject: true
@@ -458,10 +447,35 @@ pageContextNominalPageInit, httpRequestId, pageContextErrorPageInit, globalConte
458
447
  (0, utils_js_1.assert)(pageContextAbort.abortStatusCode);
459
448
  return { pageContextAbort };
460
449
  }
461
- async function assertBaseUrl(pageContextInit, globalContext) {
450
+ async function checkBaseUrl(pageContextInit, globalContext) {
462
451
  const { baseServer } = globalContext;
463
452
  const { urlOriginal } = pageContextInit;
464
- const { urlWithoutPageContextRequestSuffix } = (0, handlePageContextRequestUrl_js_1.handlePageContextRequestUrl)(urlOriginal);
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)`);
453
+ const { isBaseMissing } = (0, utils_js_1.parseUrl)(urlOriginal, baseServer);
454
+ if (!isBaseMissing)
455
+ return;
456
+ const pageContext = createPageContext(pageContextInit);
457
+ const httpResponse = (0, createHttpResponse_js_1.createHttpResponseBaseIsMissing)(urlOriginal, baseServer);
458
+ (0, utils_js_1.objectAssign)(pageContext, {
459
+ httpResponse,
460
+ isBaseMissing: true
461
+ });
462
+ (0, utils_js_1.checkType)(pageContext);
463
+ return pageContext;
464
+ }
465
+ function renderInvalidRequest(pageContextInit) {
466
+ const urlPathnameWithBase = (0, utils_js_1.parseUrl)(pageContextInit.urlOriginal, '/').pathname;
467
+ assertIsNotViteRequest(urlPathnameWithBase, pageContextInit.urlOriginal);
468
+ if (urlPathnameWithBase.endsWith('/favicon.ico')) {
469
+ const pageContext = createPageContext(pageContextInit);
470
+ const httpResponse = (0, createHttpResponse_js_1.createHttpResponseFavicon404)();
471
+ (0, utils_js_1.objectAssign)(pageContext, { httpResponse });
472
+ (0, utils_js_1.checkType)(pageContext);
473
+ return pageContext;
474
+ }
475
+ return null;
476
+ }
477
+ function renderInvalidVikeConfig(err, pageContextInit, httpRequestId) {
478
+ (0, loggerRuntime_js_1.logRuntimeInfo)?.(picocolors_1.default.bold(picocolors_1.default.red('Error while loading a Vike config file, see error above.')), httpRequestId, 'error');
479
+ const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
480
+ return pageContextWithError;
467
481
  }
@@ -9,7 +9,7 @@ exports.pageContextJsonFileExtension = pageContextJsonFileExtension;
9
9
  // `/some-base-url/index.pageContext.json` instead of `/some-base-url.pageContext.json` in order to comply to common reverse proxy setups, see https://github.com/vikejs/vike/issues/443
10
10
  const doNotCreateExtraDirectory = false;
11
11
  exports.doNotCreateExtraDirectory = doNotCreateExtraDirectory;
12
- // See node/renderPage/handlePageContextRequestUrl.ts
12
+ // See also node/renderPage/handlePageContextRequestUrl.ts
13
13
  function getPageContextRequestUrl(url) {
14
14
  const pageContextRequestUrl = (0, urlToFile_js_1.urlToFile)(url, pageContextJsonFileExtension, doNotCreateExtraDirectory);
15
15
  return pageContextRequestUrl;
@@ -39,26 +39,29 @@ function getUrlParsed(pageContext) {
39
39
  // 6. The value of pageContext.urlPathname is now '/login': the pathname of `pageContext.urlLogical`. (While pageContext.urlOriginal is still '/fr-FR/admin'.)
40
40
  // Reproduction: https://github.com/vikejs/vike/discussions/1436#discussioncomment-8142023
41
41
  // Determine logical URL
42
- // TODO/soon: revert https://github.com/vikejs/vike/issues/2138#issuecomment-2631713411
43
- const assertUrlResolved = (src) => (0, utils_js_1.assert)(urlResolved && typeof urlResolved === 'string', { src, urlResolved });
42
+ const assertUrlResolved = (src) => (0, utils_js_1.assert)(urlResolved && typeof urlResolved === 'string',
43
+ // TODO/eventually: remove debug logs, see:
44
+ // - https://github.com/vikejs/vike/issues/2138#issuecomment-2631713411
45
+ // - https://github.com/vikejs/vike/commit/5c7810f3080ab62536950f26e019bb2a3a517082
46
+ { src, urlResolved });
44
47
  let urlResolved;
45
- let baseToBeRemoved;
48
+ let isBaseToBeRemoved;
46
49
  if (pageContext.urlLogical) {
47
50
  // Set by onBeforeRoute()
48
51
  urlResolved = pageContext.urlLogical;
49
- baseToBeRemoved = false;
52
+ isBaseToBeRemoved = false;
50
53
  assertUrlResolved(1);
51
54
  }
52
55
  else if (pageContext._urlRewrite) {
53
56
  // Set by `throw render()`
54
57
  urlResolved = pageContext._urlRewrite;
55
- baseToBeRemoved = false;
58
+ isBaseToBeRemoved = false;
56
59
  assertUrlResolved(2);
57
60
  }
58
61
  else {
59
62
  // Set by renderPage()
60
63
  urlResolved = pageContext.urlOriginal;
61
- baseToBeRemoved = true;
64
+ isBaseToBeRemoved = true;
62
65
  assertUrlResolved(3);
63
66
  }
64
67
  assertUrlResolved(4);
@@ -71,7 +74,7 @@ function getUrlParsed(pageContext) {
71
74
  // - We assume there isn't any Base URL to the URLs set by the user at `throw render()` and onBeforeRoute()
72
75
  // - 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).
73
76
  // - pageContext.urlOriginal is the URL of the HTTP request and thus contains the Base URL.
74
- const baseServer = !baseToBeRemoved ? '/' : pageContext._baseServer;
77
+ const baseServer = !isBaseToBeRemoved ? '/' : pageContext._baseServer;
75
78
  // Parse URL
76
79
  return (0, utils_js_1.parseUrl)(urlResolved, baseServer);
77
80
  }
@@ -14,7 +14,7 @@ const helpers_js_1 = require("../page-configs/helpers.js");
14
14
  const getConfigValueRuntime_js_1 = require("../page-configs/getConfigValueRuntime.js");
15
15
  const utils_js_1 = require("../utils.js");
16
16
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
17
- const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('getHook.ts', {});
17
+ const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('hooks/getHook.ts', {});
18
18
  function getHook(pageContext, hookName) {
19
19
  if (!(hookName in pageContext.exports)) {
20
20
  return null;
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.222-commit-ce4e16e';
5
+ exports.PROJECT_VERSION = '0.4.222-commit-fab3841';
@@ -21,7 +21,7 @@ const isVitest_js_1 = require("./isVitest.js");
21
21
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
22
22
  (0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
23
23
  const debug = (0, debug_js_1.createDebugger)('vike:setup');
24
- const setup = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertIsNotProductionRuntime.ts', {});
24
+ const setup = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertSetup.ts', {});
25
25
  // Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
26
26
  function assertIsNotProductionRuntime() {
27
27
  if (debug.isActivated)
@@ -16,7 +16,7 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
16
16
  /* Use original assertUsage() & assertWarning() after all CJS is removed from node_modules/vike/dist/
17
17
  import { assertUsage, assertWarning } from './assert.js'
18
18
  */
19
- const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('assertSingleInstance.ts', {
19
+ const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertSingleInstance.ts', {
20
20
  instances: [],
21
21
  alreadyLogged: new Set()
22
22
  });
@@ -4,17 +4,13 @@ exports.getGlobalObject = getGlobalObject;
4
4
  exports.assertIsSingleModuleInstance = assertIsSingleModuleInstance;
5
5
  const assert_js_1 = require("./assert.js");
6
6
  /** Share information across module instances. */
7
- function getGlobalObject(
8
- // We use the filename (or file path) as key. There should be only one getGlobalObject() usage per file. Thus the key should be unique, assuming the filename (or file path) is unique.
9
- key, defaultValue) {
7
+ function getGlobalObject(key, defaultValue) {
10
8
  const globalObjects = getGlobalObjects();
11
9
  const globalObject = (globalObjects[key] = globalObjects[key] || defaultValue);
12
10
  return globalObject;
13
11
  }
14
12
  /** Assert that the module is instantiated only once. */
15
- function assertIsSingleModuleInstance(
16
- // We use the filename (or file path) as key.
17
- key) {
13
+ function assertIsSingleModuleInstance(key) {
18
14
  const globalObjects = getGlobalObjects();
19
15
  (0, assert_js_1.assert)(!(key in globalObjects));
20
16
  }
@@ -1,7 +1,7 @@
1
1
  export { setPageContextCurrent };
2
2
  export { getPageContextCurrent };
3
3
  import { getGlobalObject } from './utils.js';
4
- const globalObject = getGlobalObject('getPageContextCurrent.ts', {
4
+ const globalObject = getGlobalObject('client-routing-runtime/getPageContextCurrent.ts', {
5
5
  pageContextCurrent: null
6
6
  });
7
7
  function getPageContextCurrent() {
@@ -18,7 +18,7 @@ import { executeGuardHook } from '../../shared/route/executeGuardHook.js';
18
18
  import { AbortRender, isAbortPageContext } from '../../shared/route/abort.js';
19
19
  import { pageContextInitIsPassedToClient } from '../../shared/misc/pageContextInitIsPassedToClient.js';
20
20
  import { isServerSideError } from '../../shared/misc/isServerSideError.js';
21
- const globalObject = getGlobalObject('router/getPageContext.ts', {});
21
+ const globalObject = getGlobalObject('client-routing-runtime/getPageContextFromHooks.ts', {});
22
22
  // TODO/eventually: rename
23
23
  function getPageContextFromHooks_serialized() {
24
24
  const pageContextSerialized = getPageContextSerializedInHtml();
@@ -7,7 +7,7 @@ export { monkeyPatchHistoryAPI };
7
7
  import { getCurrentUrl } from '../shared/getCurrentUrl.js';
8
8
  import { assert, assertUsage, getGlobalObject, isObject } from './utils.js';
9
9
  initHistoryState(); // we redundantly call initHistoryState() to ensure it's called early
10
- const globalObject = getGlobalObject('history.ts', { previous: getHistoryInfo() });
10
+ const globalObject = getGlobalObject('client-routing-runtime/history.ts', { previous: getHistoryInfo() });
11
11
  // `window.history.state === null` when:
12
12
  // - The very first render
13
13
  // - Click on `<a href="#some-hash" />`
@@ -19,7 +19,7 @@ import { PAGE_CONTEXT_MAX_AGE_DEFAULT, getPrefetchSettings } from './prefetch/ge
19
19
  import pc from '@brillout/picocolors';
20
20
  import { normalizeUrlArgument } from './normalizeUrlArgument.js';
21
21
  assertClientRouting();
22
- const globalObject = getGlobalObject('prefetch.ts', {
22
+ const globalObject = getGlobalObject('client-routing-runtime/prefetch.ts', {
23
23
  linkPrefetchHandlerAdded: new WeakSet(),
24
24
  addLinkPrefetchHandlers_debounce: null,
25
25
  mutationObserver: new MutationObserver(addLinkPrefetchHandlers),
@@ -20,7 +20,7 @@ import { getErrorPageId } from '../../shared/error-page.js';
20
20
  import { setPageContextCurrent } from './getPageContextCurrent.js';
21
21
  import { getRouteStringParameterList } from '../../shared/route/resolveRouteString.js';
22
22
  import { getCurrentUrl } from '../shared/getCurrentUrl.js';
23
- const globalObject = getGlobalObject('renderPageClientSide.ts', (() => {
23
+ const globalObject = getGlobalObject('client-routing-runtime/renderPageClientSide.ts', (() => {
24
24
  const { promise: firstRenderStartPromise, resolve: firstRenderStartPromiseResolve } = genPromise();
25
25
  return {
26
26
  previousPageContext: null,
@@ -6,7 +6,7 @@ export { scrollRestoration_initialRenderIsDone };
6
6
  // - Firefox doesn't restore the scroll position upon page reload but does upon Cmd-Shift-T
7
7
  // See also: https://github.com/cyco130/knave/blob/e9e1bc7687848504293197f1b314b7d12ad0d228/design.md#scroll-restoration
8
8
  import { getGlobalObject, onPageHide, onPageShow } from './utils.js';
9
- const globalObject = getGlobalObject('scrollRestoration.ts', {});
9
+ const globalObject = getGlobalObject('client-routing-runtime/scrollRestoration.ts', {});
10
10
  function scrollRestoration_init() {
11
11
  // Use the native scroll restoration mechanism only for the first render
12
12
  scrollRestoration_enable();
@@ -1,7 +1,7 @@
1
1
  export { getPageContextProxyForUser };
2
2
  import { assert, assertUsage, assertWarning, getGlobalObject, getPropAccessNotation } from '../server-routing-runtime/utils.js';
3
3
  import { notSerializable } from '../../shared/notSerializable.js';
4
- const globalObject = getGlobalObject('getPageContextProxyForUser.ts', {});
4
+ const globalObject = getGlobalObject('shared/getPageContextProxyForUser.ts', {});
5
5
  /**
6
6
  * Throw error when pageContext value isn't:
7
7
  * - serializable, or
@@ -10,7 +10,7 @@ import path from 'path';
10
10
  import { assert, assertUsage, getGlobalObject, isObject, toPosixPath } from './utils.js';
11
11
  import pc from '@brillout/picocolors';
12
12
  import { clearGlobalContext } from '../runtime/globalContext.js';
13
- const globalObject = getGlobalObject('prepareViteApiCall.ts', {});
13
+ const globalObject = getGlobalObject('api/prepareViteApiCall.ts', {});
14
14
  async function prepareViteApiCall(viteConfigFromOptions, operation) {
15
15
  clear();
16
16
  setContextApiOperation(operation);
@@ -8,7 +8,7 @@ import { normalizeId } from '../shared/normalizeId.js';
8
8
  import { viteIsSSR_options } from '../shared/viteIsSSR.js';
9
9
  const extractExportNamesRE = /(\?|&)extractExportNames(?:&|$)/;
10
10
  const debug = createDebugger('vike:extractExportNames');
11
- const globalObject = getGlobalObject('extractExportNamesPlugin.ts', {});
11
+ const globalObject = getGlobalObject('plugins/extractExportNamesPlugin.ts', {});
12
12
  function extractExportNamesPlugin() {
13
13
  let isDev = false;
14
14
  return {
@@ -11,7 +11,7 @@ import { getEnvVarObject } from '../../../../shared/getEnvVarObject.js';
11
11
  const execA = promisify(exec);
12
12
  const debug = createDebugger('vike:crawl');
13
13
  assertIsNotProductionRuntime();
14
- assertIsSingleModuleInstance('crawlPlusFiles.ts');
14
+ assertIsSingleModuleInstance('getVikeConfig/crawlPlusFiles.ts');
15
15
  let gitIsNotUsable = false;
16
16
  async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem) {
17
17
  assertPosixPath(userRootDir);
@@ -8,7 +8,7 @@ export { getConfigDefinitionOptional };
8
8
  import { assertPosixPath, assert, isObject, assertUsage, assertWarning, objectEntries, hasProp, includes, assertIsNotProductionRuntime, getMostSimilar, joinEnglish, assertKeys, objectKeys, objectFromEntries, unique, isCallable, makeFirst, lowerFirst } from '../../../utils.js';
9
9
  import { configDefinitionsBuiltIn } from './getVikeConfig/configDefinitionsBuiltIn.js';
10
10
  import { getLocationId, getFilesystemRouteString, getFilesystemRouteDefinedBy, isInherited, sortAfterInheritanceOrder, applyFilesystemRoutingRootEffect } from './getVikeConfig/filesystemRouting.js';
11
- import { isConfigInvalid, isConfigInvalid_set } from '../../../../runtime/renderPage/isConfigInvalid.js';
11
+ import { isVikeConfigInvalid, isVikeConfigInvalid_set } from '../../../../runtime/renderPage/isVikeConfigInvalid.js';
12
12
  import { getViteDevServer } from '../../../../runtime/globalContext.js';
13
13
  import { logConfigError, logConfigErrorRecover } from '../../../shared/loggerNotProd.js';
14
14
  import { removeSuperfluousViteLog_enable, removeSuperfluousViteLog_disable } from '../../../shared/loggerVite/removeSuperfluousViteLog.js';
@@ -37,7 +37,7 @@ function reloadVikeConfig(config) {
37
37
  handleReloadSideEffects();
38
38
  }
39
39
  async function handleReloadSideEffects() {
40
- wasConfigInvalid = !!isConfigInvalid;
40
+ wasConfigInvalid = !!isVikeConfigInvalid;
41
41
  const vikeConfigPromisePrevious = vikeConfigPromise;
42
42
  try {
43
43
  await vikeConfigPromise;
@@ -52,7 +52,7 @@ async function handleReloadSideEffects() {
52
52
  // Let the next handleReloadSideEffects() call handle side effects
53
53
  return;
54
54
  }
55
- if (!isConfigInvalid) {
55
+ if (!isVikeConfigInvalid) {
56
56
  if (wasConfigInvalid) {
57
57
  wasConfigInvalid = false;
58
58
  logConfigErrorRecover();
@@ -105,13 +105,13 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, vikeVitePlug
105
105
  if (!hasError) {
106
106
  assert(ret);
107
107
  assert(err === undefined);
108
- isConfigInvalid_set(false);
108
+ isVikeConfigInvalid_set(false);
109
109
  return ret;
110
110
  }
111
111
  else {
112
112
  assert(ret === undefined);
113
113
  assert(err);
114
- isConfigInvalid_set({ err });
114
+ isVikeConfigInvalid_set({ err });
115
115
  if (!isDev) {
116
116
  assert(getViteDevServer() === null);
117
117
  throw err;
@@ -34,7 +34,7 @@ import { assertV1Design } from '../shared/assertV1Design.js';
34
34
  import { getPageConfigsRuntime } from '../../shared/getPageConfigsRuntime.js';
35
35
  import { resolveBase } from '../shared/resolveBase.js';
36
36
  const debug = createDebugger('vike:globalContext');
37
- const globalObject = getGlobalObject('globalContext.ts', getInitialGlobalContext());
37
+ const globalObject = getGlobalObject('runtime/globalContext.ts', getInitialGlobalContext());
38
38
  async function getGlobalContextInternal() {
39
39
  // getGlobalContextInternal() should always be called after initGlobalContext()
40
40
  assert(globalObject.isInitialized);
@@ -1,7 +1,7 @@
1
1
  export { assertNoInfiniteHttpRedirect };
2
2
  import { assert, assertUsage, getGlobalObject } from '../../utils.js';
3
3
  import pc from '@brillout/picocolors';
4
- const globalObject = getGlobalObject('assertNoInfiniteHttpRedirect.ts', {
4
+ const globalObject = getGlobalObject('createHttpResponse/assertNoInfiniteHttpRedirect.ts', {
5
5
  redirectGraph: {}
6
6
  });
7
7
  function assertNoInfiniteHttpRedirect(urlRedirectTarget, urlLogical) {
@@ -3,6 +3,7 @@ export { createHttpResponsePageContextJson };
3
3
  export { createHttpResponseError };
4
4
  export { createHttpResponseRedirect };
5
5
  export { createHttpResponseFavicon404 };
6
+ export { createHttpResponseBaseIsMissing };
6
7
  export type { HttpResponse };
7
8
  import type { GetPageAssets } from './getPageAssets.js';
8
9
  import type { HtmlRender } from '../html/renderHtml.js';
@@ -28,6 +29,7 @@ declare function createHttpResponsePage(htmlRender: HtmlRender, renderHook: null
28
29
  abortStatusCode?: AbortStatusCode;
29
30
  }): Promise<HttpResponse>;
30
31
  declare function createHttpResponseFavicon404(): HttpResponse;
32
+ declare function createHttpResponseBaseIsMissing(urlOriginal: string, baseServer: string): HttpResponse;
31
33
  declare function createHttpResponseError(pageContext: null | {
32
34
  _pageFilesAll: PageFile[];
33
35
  _pageConfigs: PageConfigRuntime[];
@@ -3,6 +3,7 @@ export { createHttpResponsePageContextJson };
3
3
  export { createHttpResponseError };
4
4
  export { createHttpResponseRedirect };
5
5
  export { createHttpResponseFavicon404 };
6
+ export { createHttpResponseBaseIsMissing };
6
7
  import { assert, assertWarning, escapeHtml } from '../utils.js';
7
8
  import { getErrorPageId, isErrorPage } from '../../../shared/error-page.js';
8
9
  import { getHttpResponseBody, getHttpResponseBodyStreamHandlers } from './getHttpResponseBody.js';
@@ -38,6 +39,29 @@ function createHttpResponseFavicon404() {
38
39
  const httpResponse = createHttpResponse(404, 'text/html;charset=utf-8', [], "<p>No favicon.ico found.</p><script>console.log('This HTTP response was generated by Vike.')</script>");
39
40
  return httpResponse;
40
41
  }
42
+ function createHttpResponseBaseIsMissing(urlOriginal, baseServer) {
43
+ const httpResponse = createHttpResponse(
44
+ // We use the error code `500` to signal a failing state because this HTTP response should never be used, see https://vike.dev/base-url#setup
45
+ // In other words: this HTTP response is expected to be generated but isn't expected to be actually used.
46
+ 500, 'text/html;charset=utf-8', [], `
47
+ <h1>Error: Base URL is missing</h1>
48
+ <p>
49
+ <a href="https://vike.dev/renderPage"><code>renderPage(pageContextInit)</code></a> called with <code>pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}</code> which doesn't start with the Base URL <code>${baseServer}</code>.
50
+ </p>
51
+ <p>
52
+ See <a href="https://vike.dev/base-url#setup">vike.dev/base-url#setup</a> for how to properly setup your server while using a Base URL.
53
+ </p>
54
+ <style>
55
+ code {
56
+ font-family: monospace;
57
+ background-color: #eaeaea;
58
+ padding: 3px 5px;
59
+ border-radius: 4px;
60
+ }
61
+ </style>
62
+ `);
63
+ return httpResponse;
64
+ }
41
65
  function createHttpResponseError(pageContext) {
42
66
  const reason = (() => {
43
67
  if (!pageContext) {
@@ -6,7 +6,7 @@ import { retrieveAssetsProd } from './getPageAssets/retrieveAssetsProd.js';
6
6
  import { inferMediaType } from './inferMediaType.js';
7
7
  import { getManifestEntry } from './getPageAssets/getManifestEntry.js';
8
8
  import { sortPageAssetsForEarlyHintsHeader } from './getPageAssets/sortPageAssetsForEarlyHintsHeader.js';
9
- const globalObject = getGlobalObject('getPageAssets.ts', {
9
+ const globalObject = getGlobalObject('renderPage/getPageAssets.ts', {
10
10
  resolveClientEntriesDev: null
11
11
  });
12
12
  async function getPageAssets(pageContext, clientDependencies, clientEntries) {
@@ -1,7 +1,7 @@
1
1
  export { handlePageContextRequestUrl };
2
2
  import { pageContextJsonFileExtension, doNotCreateExtraDirectory } from '../../../shared/getPageContextRequestUrl.js';
3
3
  import { baseServer, parseUrl, assert, slice } from '../utils.js';
4
- // See shared/getPageContextRequestUrl.ts
4
+ // See also shared/getPageContextRequestUrl.ts
5
5
  function handlePageContextRequestUrl(url) {
6
6
  if (!hasSuffix(url)) {
7
7
  return { urlWithoutPageContextRequestSuffix: url, isPageContextRequest: false };
@@ -1,7 +1,7 @@
1
1
  export { isNewError };
2
2
  export { setAlreadyLogged };
3
3
  import { getGlobalObject, isObject, isSameErrorMessage, warnIfErrorIsNotObject } from '../utils.js';
4
- const globalObject = getGlobalObject('runtime/renderPage/isNewError.ts', {
4
+ const globalObject = getGlobalObject('renderPage/isNewError.ts', {
5
5
  wasAlreadyLogged: new WeakSet()
6
6
  });
7
7
  function isNewError(errErrorPage, errNominalPage) {
@@ -0,0 +1,6 @@
1
+ export { isVikeConfigInvalid };
2
+ export { isVikeConfigInvalid_set };
3
+ declare let isVikeConfigInvalid: false | {
4
+ err: unknown;
5
+ };
6
+ declare const isVikeConfigInvalid_set: (val: typeof isVikeConfigInvalid) => void;
@@ -0,0 +1,8 @@
1
+ export { isVikeConfigInvalid };
2
+ export { isVikeConfigInvalid_set };
3
+ import { assert } from '../utils.js';
4
+ let isVikeConfigInvalid;
5
+ const isVikeConfigInvalid_set = (val) => {
6
+ assert(val === false || val.err);
7
+ isVikeConfigInvalid = val;
8
+ };
@@ -6,12 +6,12 @@ import { assert, hasProp, objectAssign, isUrl, parseUrl, onSetupRuntime, assertW
6
6
  import { assertNoInfiniteAbortLoop, getPageContextFromAllRewrites, isAbortError, logAbortErrorHandled } from '../../shared/route/abort.js';
7
7
  import { getGlobalContextInternal, initGlobalContext_renderPage } from './globalContext.js';
8
8
  import { handlePageContextRequestUrl } from './renderPage/handlePageContextRequestUrl.js';
9
- import { createHttpResponseFavicon404, createHttpResponseRedirect, createHttpResponsePageContextJson, createHttpResponseError } from './renderPage/createHttpResponse.js';
9
+ import { createHttpResponseFavicon404, createHttpResponseRedirect, createHttpResponsePageContextJson, createHttpResponseError, createHttpResponseBaseIsMissing } from './renderPage/createHttpResponse.js';
10
10
  import { logRuntimeError, logRuntimeInfo } from './renderPage/loggerRuntime.js';
11
11
  import { isNewError } from './renderPage/isNewError.js';
12
12
  import { assertArguments } from './renderPage/assertArguments.js';
13
13
  import { log404 } from './renderPage/log404/index.js';
14
- import { isConfigInvalid } from './renderPage/isConfigInvalid.js';
14
+ import { isVikeConfigInvalid } from './renderPage/isVikeConfigInvalid.js';
15
15
  import pc from '@brillout/picocolors';
16
16
  import { serializePageContextAbort, serializePageContextClientSide } from './html/serializePageContextClientSide.js';
17
17
  import { getErrorPageId } from '../../shared/error-page.js';
@@ -25,12 +25,11 @@ const globalObject = getGlobalObject('runtime/renderPage.ts', {
25
25
  async function renderPage(pageContextInit) {
26
26
  assertArguments(...arguments);
27
27
  assert(hasProp(pageContextInit, 'urlOriginal', 'string')); // assertUsage() already implemented at assertArguments()
28
- onSetupRuntime();
29
28
  assertIsUrl(pageContextInit.urlOriginal);
30
- const urlPathnameWithBase = parseUrl(pageContextInit.urlOriginal, '/').pathname;
31
- assertIsNotViteRequest(urlPathnameWithBase, pageContextInit.urlOriginal);
32
- if (urlPathnameWithBase.endsWith('/favicon.ico'))
33
- return getPageContextHttpResponseFavicon404(pageContextInit);
29
+ onSetupRuntime();
30
+ const pageContextInvalidRequest = renderInvalidRequest(pageContextInit);
31
+ if (pageContextInvalidRequest)
32
+ return pageContextInvalidRequest;
34
33
  const httpRequestId = getRequestId();
35
34
  const urlOriginalPretty = getUrlPretty(pageContextInit.urlOriginal);
36
35
  logHttpRequest(urlOriginalPretty, httpRequestId);
@@ -50,15 +49,10 @@ function renderPage_addAsyncHookwrapper(wrapper) {
50
49
  }
51
50
  async function renderPageAndPrepare(pageContextInit, httpRequestId) {
52
51
  // Invalid config
53
- const handleInvalidConfig = (err) => {
54
- logRuntimeInfo?.(pc.bold(pc.red('Error while loading a Vike config file, see error above.')), httpRequestId, 'error');
55
- const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
56
- return pageContextWithError;
57
- };
58
- if (isConfigInvalid) {
52
+ if (isVikeConfigInvalid) {
59
53
  if (1 < 2 // Make TS happy
60
54
  ) {
61
- return handleInvalidConfig(isConfigInvalid.err);
55
+ return renderInvalidVikeConfig(isVikeConfigInvalid.err, pageContextInit, httpRequestId);
62
56
  }
63
57
  }
64
58
  // Prepare context
@@ -76,15 +70,19 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
76
70
  const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
77
71
  return pageContextWithError;
78
72
  }
79
- if (isConfigInvalid) {
80
- return handleInvalidConfig(isConfigInvalid.err);
73
+ if (isVikeConfigInvalid) {
74
+ return renderInvalidVikeConfig(isVikeConfigInvalid.err, pageContextInit, httpRequestId);
81
75
  }
82
76
  else {
83
- // From now on, globalContext contains all the configuration data; getVikeConfig() isn't called anymore for this request
77
+ // `globalContext` now contains the entire Vike config and getVikeConfig() isn't called anymore for this request.
84
78
  }
85
79
  const globalContext = await getGlobalContextInternal();
86
80
  // Check Base URL
87
- await assertBaseUrl(pageContextInit, globalContext);
81
+ {
82
+ const pageContextHttpResponse = await checkBaseUrl(pageContextInit, globalContext);
83
+ if (pageContextHttpResponse)
84
+ return pageContextHttpResponse;
85
+ }
88
86
  // Normalize URL
89
87
  {
90
88
  const pageContextHttpResponse = await normalizeUrl(pageContextInit, globalContext, httpRequestId);
@@ -252,15 +250,6 @@ function getPageContextHttpResponseError(err, pageContextInit, pageContext) {
252
250
  });
253
251
  return pageContextWithError;
254
252
  }
255
- function getPageContextHttpResponseFavicon404(pageContextInit) {
256
- const pageContext = createPageContext(pageContextInit);
257
- const httpResponse = createHttpResponseFavicon404();
258
- objectAssign(pageContext, {
259
- httpResponse
260
- });
261
- checkType(pageContext);
262
- return pageContext;
263
- }
264
253
  function createPageContext(pageContextInit) {
265
254
  const pageContext = {
266
255
  _isPageContextObject: true
@@ -453,10 +442,35 @@ pageContextNominalPageInit, httpRequestId, pageContextErrorPageInit, globalConte
453
442
  assert(pageContextAbort.abortStatusCode);
454
443
  return { pageContextAbort };
455
444
  }
456
- async function assertBaseUrl(pageContextInit, globalContext) {
445
+ async function checkBaseUrl(pageContextInit, globalContext) {
457
446
  const { baseServer } = globalContext;
458
447
  const { urlOriginal } = pageContextInit;
459
- const { urlWithoutPageContextRequestSuffix } = handlePageContextRequestUrl(urlOriginal);
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)`);
448
+ const { isBaseMissing } = parseUrl(urlOriginal, baseServer);
449
+ if (!isBaseMissing)
450
+ return;
451
+ const pageContext = createPageContext(pageContextInit);
452
+ const httpResponse = createHttpResponseBaseIsMissing(urlOriginal, baseServer);
453
+ objectAssign(pageContext, {
454
+ httpResponse,
455
+ isBaseMissing: true
456
+ });
457
+ checkType(pageContext);
458
+ return pageContext;
459
+ }
460
+ function renderInvalidRequest(pageContextInit) {
461
+ const urlPathnameWithBase = parseUrl(pageContextInit.urlOriginal, '/').pathname;
462
+ assertIsNotViteRequest(urlPathnameWithBase, pageContextInit.urlOriginal);
463
+ if (urlPathnameWithBase.endsWith('/favicon.ico')) {
464
+ const pageContext = createPageContext(pageContextInit);
465
+ const httpResponse = createHttpResponseFavicon404();
466
+ objectAssign(pageContext, { httpResponse });
467
+ checkType(pageContext);
468
+ return pageContext;
469
+ }
470
+ return null;
471
+ }
472
+ function renderInvalidVikeConfig(err, pageContextInit, httpRequestId) {
473
+ logRuntimeInfo?.(pc.bold(pc.red('Error while loading a Vike config file, see error above.')), httpRequestId, 'error');
474
+ const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
475
+ return pageContextWithError;
462
476
  }
@@ -6,7 +6,7 @@ import { urlToFile } from '../utils/urlToFile.js';
6
6
  const pageContextJsonFileExtension = '.pageContext.json';
7
7
  // `/some-base-url/index.pageContext.json` instead of `/some-base-url.pageContext.json` in order to comply to common reverse proxy setups, see https://github.com/vikejs/vike/issues/443
8
8
  const doNotCreateExtraDirectory = false;
9
- // See node/renderPage/handlePageContextRequestUrl.ts
9
+ // See also node/renderPage/handlePageContextRequestUrl.ts
10
10
  function getPageContextRequestUrl(url) {
11
11
  const pageContextRequestUrl = urlToFile(url, pageContextJsonFileExtension, doNotCreateExtraDirectory);
12
12
  return pageContextRequestUrl;
@@ -37,26 +37,29 @@ function getUrlParsed(pageContext) {
37
37
  // 6. The value of pageContext.urlPathname is now '/login': the pathname of `pageContext.urlLogical`. (While pageContext.urlOriginal is still '/fr-FR/admin'.)
38
38
  // Reproduction: https://github.com/vikejs/vike/discussions/1436#discussioncomment-8142023
39
39
  // Determine logical URL
40
- // TODO/soon: revert https://github.com/vikejs/vike/issues/2138#issuecomment-2631713411
41
- const assertUrlResolved = (src) => assert(urlResolved && typeof urlResolved === 'string', { src, urlResolved });
40
+ const assertUrlResolved = (src) => assert(urlResolved && typeof urlResolved === 'string',
41
+ // TODO/eventually: remove debug logs, see:
42
+ // - https://github.com/vikejs/vike/issues/2138#issuecomment-2631713411
43
+ // - https://github.com/vikejs/vike/commit/5c7810f3080ab62536950f26e019bb2a3a517082
44
+ { src, urlResolved });
42
45
  let urlResolved;
43
- let baseToBeRemoved;
46
+ let isBaseToBeRemoved;
44
47
  if (pageContext.urlLogical) {
45
48
  // Set by onBeforeRoute()
46
49
  urlResolved = pageContext.urlLogical;
47
- baseToBeRemoved = false;
50
+ isBaseToBeRemoved = false;
48
51
  assertUrlResolved(1);
49
52
  }
50
53
  else if (pageContext._urlRewrite) {
51
54
  // Set by `throw render()`
52
55
  urlResolved = pageContext._urlRewrite;
53
- baseToBeRemoved = false;
56
+ isBaseToBeRemoved = false;
54
57
  assertUrlResolved(2);
55
58
  }
56
59
  else {
57
60
  // Set by renderPage()
58
61
  urlResolved = pageContext.urlOriginal;
59
- baseToBeRemoved = true;
62
+ isBaseToBeRemoved = true;
60
63
  assertUrlResolved(3);
61
64
  }
62
65
  assertUrlResolved(4);
@@ -69,7 +72,7 @@ function getUrlParsed(pageContext) {
69
72
  // - We assume there isn't any Base URL to the URLs set by the user at `throw render()` and onBeforeRoute()
70
73
  // - 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).
71
74
  // - pageContext.urlOriginal is the URL of the HTTP request and thus contains the Base URL.
72
- const baseServer = !baseToBeRemoved ? '/' : pageContext._baseServer;
75
+ const baseServer = !isBaseToBeRemoved ? '/' : pageContext._baseServer;
73
76
  // Parse URL
74
77
  return parseUrl(urlResolved, baseServer);
75
78
  }
@@ -11,7 +11,7 @@ import { getHookFilePathToShowToUser } from '../page-configs/helpers.js';
11
11
  import { getConfigValueRuntime } from '../page-configs/getConfigValueRuntime.js';
12
12
  import { assert, assertUsage, checkType, isCallable, isObject } from '../utils.js';
13
13
  import pc from '@brillout/picocolors';
14
- const globalObject = getGlobalObject('getHook.ts', {});
14
+ const globalObject = getGlobalObject('hooks/getHook.ts', {});
15
15
  function getHook(pageContext, hookName) {
16
16
  if (!(hookName in pageContext.exports)) {
17
17
  return null;
@@ -131,6 +131,12 @@ type PageContextBuiltInCommon<Data> = {
131
131
  url: string;
132
132
  /** @deprecated */
133
133
  pageExports: Record<string, unknown>;
134
+ /**
135
+ * Whether the Base URL is missing in the URL of the HTTP request made to the SSR server.
136
+ *
137
+ * https://vike.dev/base-url#setup
138
+ */
139
+ isBaseMissing?: true;
134
140
  };
135
141
  type PageContextBuiltInServer<Data> = PageContextBuiltInCommon<Data> & PageContextUrlServer;
136
142
  type PageContextBuiltInClientWithClientRouting<Data> = Partial<PageContextBuiltInCommon<Data>> & Pick<PageContextBuiltInCommon<Data>, 'Page' | 'routeParams' | 'pageExports' | 'config' | 'configEntries' | 'exports' | 'exportsAll' | 'abortReason' | 'data' | 'pageId' | 'source' | 'sources' | 'from'> & {
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.222-commit-ce4e16e";
1
+ export declare const PROJECT_VERSION: "0.4.222-commit-fab3841";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.222-commit-ce4e16e';
2
+ export const PROJECT_VERSION = '0.4.222-commit-fab3841';
@@ -16,7 +16,7 @@ import { isVitest } from './isVitest.js';
16
16
  import pc from '@brillout/picocolors';
17
17
  assertIsNotBrowser();
18
18
  const debug = createDebugger('vike:setup');
19
- const setup = getGlobalObject('utils/assertIsNotProductionRuntime.ts', {});
19
+ const setup = getGlobalObject('utils/assertSetup.ts', {});
20
20
  // Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
21
21
  function assertIsNotProductionRuntime() {
22
22
  if (debug.isActivated)
@@ -11,7 +11,7 @@ import pc from '@brillout/picocolors';
11
11
  /* Use original assertUsage() & assertWarning() after all CJS is removed from node_modules/vike/dist/
12
12
  import { assertUsage, assertWarning } from './assert.js'
13
13
  */
14
- const globalObject = getGlobalObject('assertSingleInstance.ts', {
14
+ const globalObject = getGlobalObject('utils/assertSingleInstance.ts', {
15
15
  instances: [],
16
16
  alreadyLogged: new Set()
17
17
  });
@@ -1,6 +1,7 @@
1
1
  export { getGlobalObject };
2
2
  export { assertIsSingleModuleInstance };
3
+ type Key = `${string}/${string}.ts`;
3
4
  /** Share information across module instances. */
4
- declare function getGlobalObject<T extends Record<string, unknown> = never>(key: `${string}.ts`, defaultValue: T): T;
5
+ declare function getGlobalObject<T extends Record<string, unknown> = never>(key: Key, defaultValue: T): T;
5
6
  /** Assert that the module is instantiated only once. */
6
- declare function assertIsSingleModuleInstance(key: `${string}.ts`): void;
7
+ declare function assertIsSingleModuleInstance(key: Key): void;
@@ -2,17 +2,13 @@ export { getGlobalObject };
2
2
  export { assertIsSingleModuleInstance };
3
3
  import { assert } from './assert.js';
4
4
  /** Share information across module instances. */
5
- function getGlobalObject(
6
- // We use the filename (or file path) as key. There should be only one getGlobalObject() usage per file. Thus the key should be unique, assuming the filename (or file path) is unique.
7
- key, defaultValue) {
5
+ function getGlobalObject(key, defaultValue) {
8
6
  const globalObjects = getGlobalObjects();
9
7
  const globalObject = (globalObjects[key] = globalObjects[key] || defaultValue);
10
8
  return globalObject;
11
9
  }
12
10
  /** Assert that the module is instantiated only once. */
13
- function assertIsSingleModuleInstance(
14
- // We use the filename (or file path) as key.
15
- key) {
11
+ function assertIsSingleModuleInstance(key) {
16
12
  const globalObjects = getGlobalObjects();
17
13
  assert(!(key in globalObjects));
18
14
  }
@@ -1,4 +1,4 @@
1
1
  export declare const projectInfo: {
2
2
  projectName: "Vike";
3
- projectVersion: "0.4.222-commit-ce4e16e";
3
+ projectVersion: "0.4.222-commit-fab3841";
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.222-commit-ce4e16e",
3
+ "version": "0.4.222-commit-fab3841",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isConfigInvalid_set = exports.isConfigInvalid = void 0;
4
- const utils_js_1 = require("../utils.js");
5
- let isConfigInvalid;
6
- const isConfigInvalid_set = (val) => {
7
- (0, utils_js_1.assert)(val === false || val.err);
8
- exports.isConfigInvalid = isConfigInvalid = val;
9
- };
10
- exports.isConfigInvalid_set = isConfigInvalid_set;
@@ -1,6 +0,0 @@
1
- export { isConfigInvalid };
2
- export { isConfigInvalid_set };
3
- declare let isConfigInvalid: false | {
4
- err: unknown;
5
- };
6
- declare const isConfigInvalid_set: (val: typeof isConfigInvalid) => void;
@@ -1,8 +0,0 @@
1
- export { isConfigInvalid };
2
- export { isConfigInvalid_set };
3
- import { assert } from '../utils.js';
4
- let isConfigInvalid;
5
- const isConfigInvalid_set = (val) => {
6
- assert(val === false || val.err);
7
- isConfigInvalid = val;
8
- };