@nocobase/app 2.2.0-beta.14 → 2.2.0-beta.15
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/client/public/browser-checker.js +58 -0
- package/client/rsbuild.config.ts +9 -0
- package/client-v2/rsbuild.config.ts +53 -0
- package/dist/client/assets/{index-055abdff.js → index-967a3036.js} +425 -350
- package/dist/client/browser-checker.js +58 -0
- package/dist/client/index.html +3 -1
- package/dist/client/index.html.tpl +3 -1
- package/dist/client/v/assets/{index-66c7433f.js → index-e5cd21f6.js} +237 -162
- package/dist/client/v/index.html +1 -1
- package/package.json +7 -7
- /package/dist/client/assets/{index-055abdff.js.LICENSE.txt → index-967a3036.js.LICENSE.txt} +0 -0
- /package/dist/client/v/assets/{index-66c7433f.js.LICENSE.txt → index-e5cd21f6.js.LICENSE.txt} +0 -0
|
@@ -17,9 +17,31 @@ 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
|
+
|
|
20
37
|
const basename = normalizePublicPath(window['__nocobase_public_path__'] || '/');
|
|
21
38
|
const currentPath = ensureLeadingSlash(String(window.location.pathname || '/').trim() || '/').replace(/\/{2,}/g, '/');
|
|
22
39
|
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__'];
|
|
23
45
|
|
|
24
46
|
if (basename !== '/' && currentPath === basenameWithoutTrailingSlash) {
|
|
25
47
|
const newUrl = `${window.location.origin}${basename}${window.location.search}${window.location.hash}`;
|
|
@@ -28,6 +50,42 @@ if (basename !== '/' && currentPath === basenameWithoutTrailingSlash) {
|
|
|
28
50
|
const newPath = currentPath === '/' ? basename : `${basenameWithoutTrailingSlash}${currentPath}`;
|
|
29
51
|
let newUrl = window.location.origin + newPath + window.location.search + window.location.hash;
|
|
30
52
|
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
|
+
}
|
|
31
89
|
}
|
|
32
90
|
let showLog = true;
|
|
33
91
|
function log(m) {
|
package/client/rsbuild.config.ts
CHANGED
|
@@ -47,9 +47,16 @@ 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;
|
|
50
55
|
if (!isBuild) {
|
|
51
56
|
return [
|
|
52
57
|
`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)};`,
|
|
53
60
|
`window['__nocobase_dev_public_path__'] = "/";`,
|
|
54
61
|
`window['__nocobase_app_dev__'] = ${JSON.stringify(process.env.NOCOBASE_APP_DEV === 'true')};`,
|
|
55
62
|
`window['__esm_cdn_base_url__'] = ${JSON.stringify(process.env.ESM_CDN_BASE_URL || '')};`,
|
|
@@ -60,6 +67,8 @@ function createRuntimeHeadScript(appPublicPath: string, isBuild: boolean) {
|
|
|
60
67
|
return [
|
|
61
68
|
`window['__webpack_public_path__'] = '{{env.CDN_BASE_URL}}';`,
|
|
62
69
|
`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}}';`,
|
|
63
72
|
`window['__nocobase_api_base_url__'] = '{{env.API_BASE_URL}}';`,
|
|
64
73
|
`window['__nocobase_api_client_storage_prefix__'] = '{{env.API_CLIENT_STORAGE_PREFIX}}';`,
|
|
65
74
|
`window['__nocobase_api_client_storage_type__'] = '{{env.API_CLIENT_STORAGE_TYPE}}';`,
|
|
@@ -52,6 +52,27 @@ 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
|
+
|
|
55
76
|
function createRuntimeHeadScript(v2PublicPath: string, isBuild: boolean, modernClientPrefix: string) {
|
|
56
77
|
if (!isBuild) {
|
|
57
78
|
return [
|
|
@@ -133,6 +154,7 @@ export default defineConfig(({ command }) => {
|
|
|
133
154
|
const modernClientDistPath = ensurePublicPath(`${appPublicPath.replace(/\/$/, '')}/${MODERN_CLIENT_DIST_DIR}/`);
|
|
134
155
|
const modernClientPublicPath = ensurePublicPath(`${appPublicPath.replace(/\/$/, '')}/${modernClientPrefix}/`);
|
|
135
156
|
const v2PublicPath = isBuild ? modernClientDistPath : modernClientPublicPath;
|
|
157
|
+
const appClientEntryMode = process.env.APP_CLIENT_ENTRY_MODE;
|
|
136
158
|
const wsBasePath = ensurePublicPath(process.env.WS_PATH || '/ws/');
|
|
137
159
|
const hmrPath = `${v2PublicPath.replace(/\/$/, '')}/__rspack_hmr`;
|
|
138
160
|
const v2Port = toNumber(process.env.APP_V2_PORT, 13002);
|
|
@@ -280,6 +302,37 @@ export default defineConfig(({ command }) => {
|
|
|
280
302
|
dev: {
|
|
281
303
|
assetPrefix: v2PublicPath,
|
|
282
304
|
lazyCompilation: false,
|
|
305
|
+
setupMiddlewares: [
|
|
306
|
+
(middlewares) => {
|
|
307
|
+
if (appClientEntryMode !== 'modern-only') {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
middlewares.unshift((req, res, next) => {
|
|
312
|
+
const [rawPathname = '/', query = ''] = String(req.url || '/').split('?');
|
|
313
|
+
const pathname = normalizePathname(rawPathname);
|
|
314
|
+
if (
|
|
315
|
+
!isClientDocumentEntryPath(pathname) ||
|
|
316
|
+
pathname.startsWith('/.well-known/') ||
|
|
317
|
+
pathname.startsWith(apiBasePath) ||
|
|
318
|
+
pathname.startsWith(wsBasePath) ||
|
|
319
|
+
pathname.startsWith(localStorageBasePath) ||
|
|
320
|
+
pathname.startsWith(staticBasePath)
|
|
321
|
+
) {
|
|
322
|
+
next();
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (!isWithinBasePath(pathname, v2PublicPath)) {
|
|
326
|
+
const target = pathname === '/' ? v2PublicPath : `${v2PublicPath.replace(/\/$/, '')}${pathname}`;
|
|
327
|
+
res.statusCode = 302;
|
|
328
|
+
res.setHeader('Location', `${target}${query ? `?${query}` : ''}`);
|
|
329
|
+
res.end();
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
next();
|
|
333
|
+
});
|
|
334
|
+
},
|
|
335
|
+
],
|
|
283
336
|
client: {
|
|
284
337
|
overlay: false,
|
|
285
338
|
protocol: 'ws',
|