@nocobase/app 2.2.0-alpha.7 → 2.2.0-beta.10

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.
@@ -17,31 +17,9 @@ function normalizePublicPath(value) {
17
17
  return ensureTrailingSlash(normalized);
18
18
  }
19
19
 
20
- function trimTrailingSlash(value) {
21
- return value === '/' ? value : value.replace(/\/+$/g, '');
22
- }
23
-
24
- function normalizePathname(value) {
25
- const normalized = ensureLeadingSlash(String(value || '/').trim() || '/').replace(/\/{2,}/g, '/');
26
- if (normalized !== '/' && normalized.endsWith('/')) {
27
- return normalized.replace(/\/+$/g, '');
28
- }
29
- return normalized;
30
- }
31
-
32
- function isClientDocumentEntryPath(pathname) {
33
- const normalized = normalizePathname(pathname);
34
- return normalized === '/' || normalized === '/index.html' || !/\.[^/]+$/.test(normalized);
35
- }
36
-
37
20
  const basename = normalizePublicPath(window['__nocobase_public_path__'] || '/');
38
21
  const currentPath = ensureLeadingSlash(String(window.location.pathname || '/').trim() || '/').replace(/\/{2,}/g, '/');
39
22
  const basenameWithoutTrailingSlash = basename === '/' ? '/' : basename.replace(/\/+$/, '');
40
- const modernClientPrefix =
41
- String(window['__nocobase_modern_client_prefix__'] || 'v')
42
- .trim()
43
- .replace(/^\/+|\/+$/g, '') || 'v';
44
- const appClientEntryMode = window['__nocobase_app_client_entry_mode__'];
45
23
 
46
24
  if (basename !== '/' && currentPath === basenameWithoutTrailingSlash) {
47
25
  const newUrl = `${window.location.origin}${basename}${window.location.search}${window.location.hash}`;
@@ -50,42 +28,6 @@ if (basename !== '/' && currentPath === basenameWithoutTrailingSlash) {
50
28
  const newPath = currentPath === '/' ? basename : `${basenameWithoutTrailingSlash}${currentPath}`;
51
29
  let newUrl = window.location.origin + newPath + window.location.search + window.location.hash;
52
30
  window.location.replace(newUrl);
53
- } else {
54
- // This client-side redirect is still needed because legacy `index.html` is
55
- // not always served through the node gateway. In nginx/static delivery paths
56
- // the browser may already be running the legacy shell by the time entry-mode
57
- // logic is evaluated, so the last hop into the modern entry has to be
58
- // recoverable in the browser as well.
59
- const normalizedPath = normalizePathname(currentPath);
60
- const relativePath =
61
- basename === '/'
62
- ? normalizedPath
63
- : normalizedPath === basenameWithoutTrailingSlash
64
- ? '/'
65
- : normalizedPath.startsWith(basename)
66
- ? normalizePathname(normalizedPath.slice(basename.length - 1))
67
- : null;
68
- const modernBase = `${trimTrailingSlash(basename)}/${modernClientPrefix}/`.replace(/\/{2,}/g, '/');
69
- const isModernDefault = appClientEntryMode === 'modern-default';
70
- const isModernOnly = appClientEntryMode === 'modern-only';
71
- if (
72
- relativePath &&
73
- isClientDocumentEntryPath(relativePath) &&
74
- (isModernDefault || isModernOnly) &&
75
- !normalizedPath.startsWith(modernBase)
76
- ) {
77
- const targetPath = isModernDefault
78
- ? relativePath === '/' || relativePath === '/index.html'
79
- ? relativePath === '/index.html'
80
- ? `${modernBase}index.html`
81
- : modernBase
82
- : null
83
- : `${trimTrailingSlash(modernBase)}${relativePath}`;
84
- if (targetPath && targetPath !== currentPath) {
85
- const newUrl = window.location.origin + targetPath + window.location.search + window.location.hash;
86
- window.location.replace(newUrl);
87
- }
88
- }
89
31
  }
90
32
  let showLog = true;
91
33
  function log(m) {
@@ -47,16 +47,9 @@ function toDefineLiteral(value: string | undefined) {
47
47
  }
48
48
 
49
49
  function createRuntimeHeadScript(appPublicPath: string, isBuild: boolean) {
50
- const modernClientPrefix =
51
- String(process.env.APP_MODERN_CLIENT_PREFIX || 'v')
52
- .trim()
53
- .replace(/^\/+|\/+$/g, '') || 'v';
54
- const appClientEntryMode = process.env.APP_CLIENT_ENTRY_MODE;
55
50
  if (!isBuild) {
56
51
  return [
57
52
  `window['__nocobase_public_path__'] = ${JSON.stringify(appPublicPath)};`,
58
- `window['__nocobase_modern_client_prefix__'] = ${JSON.stringify(modernClientPrefix)};`,
59
- `window['__nocobase_app_client_entry_mode__'] = ${JSON.stringify(appClientEntryMode)};`,
60
53
  `window['__nocobase_dev_public_path__'] = "/";`,
61
54
  `window['__nocobase_app_dev__'] = ${JSON.stringify(process.env.NOCOBASE_APP_DEV === 'true')};`,
62
55
  `window['__esm_cdn_base_url__'] = ${JSON.stringify(process.env.ESM_CDN_BASE_URL || '')};`,
@@ -67,8 +60,6 @@ function createRuntimeHeadScript(appPublicPath: string, isBuild: boolean) {
67
60
  return [
68
61
  `window['__webpack_public_path__'] = '{{env.CDN_BASE_URL}}';`,
69
62
  `window['__nocobase_public_path__'] = '${appPublicPath}';`,
70
- `window['__nocobase_modern_client_prefix__'] = '{{env.APP_MODERN_CLIENT_PREFIX}}';`,
71
- `window['__nocobase_app_client_entry_mode__'] = '{{env.APP_CLIENT_ENTRY_MODE}}';`,
72
63
  `window['__nocobase_api_base_url__'] = '{{env.API_BASE_URL}}';`,
73
64
  `window['__nocobase_api_client_storage_prefix__'] = '{{env.API_CLIENT_STORAGE_PREFIX}}';`,
74
65
  `window['__nocobase_api_client_storage_type__'] = '{{env.API_CLIENT_STORAGE_TYPE}}';`,
@@ -52,27 +52,6 @@ function toNumber(value: string | undefined, fallback: number) {
52
52
  return Number.isFinite(parsed) ? parsed : fallback;
53
53
  }
54
54
 
55
- function normalizePathname(value: string | undefined) {
56
- let normalized = value || '/';
57
- if (!normalized.startsWith('/')) {
58
- normalized = `/${normalized}`;
59
- }
60
- normalized = normalized.replace(/\/{2,}/g, '/');
61
- if (normalized !== '/' && normalized.endsWith('/')) {
62
- return normalized.replace(/\/+$/g, '');
63
- }
64
- return normalized || '/';
65
- }
66
-
67
- function isClientDocumentEntryPath(pathname: string) {
68
- return pathname === '/' || pathname === '/index.html' || !/\.[^/]+$/.test(pathname);
69
- }
70
-
71
- function isWithinBasePath(pathname: string, basePath: string) {
72
- const normalizedBasePath = normalizePathname(basePath);
73
- return pathname === normalizedBasePath || pathname.startsWith(`${normalizedBasePath}/`);
74
- }
75
-
76
55
  function createRuntimeHeadScript(v2PublicPath: string, isBuild: boolean, modernClientPrefix: string) {
77
56
  if (!isBuild) {
78
57
  return [
@@ -153,7 +132,6 @@ export default defineConfig(({ command }) => {
153
132
  const modernClientDistPath = ensurePublicPath(`${appPublicPath.replace(/\/$/, '')}/${MODERN_CLIENT_DIST_DIR}/`);
154
133
  const modernClientPublicPath = ensurePublicPath(`${appPublicPath.replace(/\/$/, '')}/${modernClientPrefix}/`);
155
134
  const v2PublicPath = isBuild ? modernClientDistPath : modernClientPublicPath;
156
- const appClientEntryMode = process.env.APP_CLIENT_ENTRY_MODE;
157
135
  const wsBasePath = ensurePublicPath(process.env.WS_PATH || '/ws/');
158
136
  const hmrPath = `${v2PublicPath.replace(/\/$/, '')}/__rspack_hmr`;
159
137
  const v2Port = toNumber(process.env.APP_V2_PORT, 13002);
@@ -297,37 +275,6 @@ export default defineConfig(({ command }) => {
297
275
  dev: {
298
276
  assetPrefix: v2PublicPath,
299
277
  lazyCompilation: false,
300
- setupMiddlewares: [
301
- (middlewares) => {
302
- if (appClientEntryMode !== 'modern-only') {
303
- return;
304
- }
305
-
306
- middlewares.unshift((req, res, next) => {
307
- const [rawPathname = '/', query = ''] = String(req.url || '/').split('?');
308
- const pathname = normalizePathname(rawPathname);
309
- if (
310
- !isClientDocumentEntryPath(pathname) ||
311
- pathname.startsWith('/.well-known/') ||
312
- pathname.startsWith(apiBasePath) ||
313
- pathname.startsWith(wsBasePath) ||
314
- pathname.startsWith(localStorageBasePath) ||
315
- pathname.startsWith(staticBasePath)
316
- ) {
317
- next();
318
- return;
319
- }
320
- if (!isWithinBasePath(pathname, v2PublicPath)) {
321
- const target = pathname === '/' ? v2PublicPath : `${v2PublicPath.replace(/\/$/, '')}${pathname}`;
322
- res.statusCode = 302;
323
- res.setHeader('Location', `${target}${query ? `?${query}` : ''}`);
324
- res.end();
325
- return;
326
- }
327
- next();
328
- });
329
- },
330
- ],
331
278
  client: {
332
279
  overlay: false,
333
280
  protocol: 'ws',