@nocobase/server 2.3.0-beta.5 → 2.4.0-alpha.1

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.
@@ -59,6 +59,7 @@ export declare class Gateway extends EventEmitter {
59
59
  private host;
60
60
  private socketPath;
61
61
  private v2IndexTemplateCache;
62
+ private settingsIndexTemplateCache;
62
63
  private terminating;
63
64
  private getOriginalRequestUrl;
64
65
  private proxyRequestToSubApp;
@@ -80,6 +81,18 @@ export declare class Gateway extends EventEmitter {
80
81
  responseErrorWithCode(code: any, res: any, options: any): void;
81
82
  private getV2PublicPath;
82
83
  private getAppPublicPath;
84
+ private getSettingsPublicPath;
85
+ private getPathWithinAppPublicPath;
86
+ private isSettingsRequest;
87
+ private isSettingsIndexRequest;
88
+ private isSettingsAssetsRequest;
89
+ private resolveLegacyV2SettingsRedirect;
90
+ private getPortalRootPublicPath;
91
+ private getPortalAppPublicPath;
92
+ private resolvePortalRootEntryRedirect;
93
+ private getPortalMatch;
94
+ private isPortalIndexRequest;
95
+ private getPortalDistRoot;
83
96
  private isV2Request;
84
97
  private isV2IndexRequest;
85
98
  private getV2RuntimeConfig;
@@ -87,6 +100,11 @@ export declare class Gateway extends EventEmitter {
87
100
  private getV2AssetPublicPath;
88
101
  private getV2IndexTemplate;
89
102
  private renderV2IndexHtml;
103
+ private getSettingsRuntimeConfig;
104
+ private getSettingsRuntimeConfigScript;
105
+ private getSettingsAssetPublicPath;
106
+ private getSettingsIndexTemplate;
107
+ private renderSettingsIndexHtml;
90
108
  requestHandler(req: IncomingMessage, res: ServerResponse): Promise<void>;
91
109
  getAppSelectorMiddlewares(): Toposort<AppSelectorMiddleware>;
92
110
  getRequestHandleAppName(req: IncomingMessage | IncomingRequest): Promise<string>;
@@ -114,6 +114,7 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
114
114
  host = "0.0.0.0";
115
115
  socketPath = getSocketPath();
116
116
  v2IndexTemplateCache = null;
117
+ settingsIndexTemplateCache = null;
117
118
  terminating = false;
118
119
  getOriginalRequestUrl(req) {
119
120
  return req.originalUrl || req.url;
@@ -156,6 +157,7 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
156
157
  }, "onTerminate");
157
158
  constructor() {
158
159
  super();
160
+ (0, import_utils3.normalizeModernClientPrefix)(import_node_process.default.env.APP_MODERN_CLIENT_PREFIX);
159
161
  this.reset();
160
162
  import_node_process.default.once("SIGTERM", this.onTerminate);
161
163
  import_node_process.default.once("SIGINT", this.onTerminate);
@@ -188,19 +190,28 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
188
190
  this.selectorMiddlewares = new import_utils.Toposort();
189
191
  this.addAppSelectorMiddleware(
190
192
  async (ctx, next) => {
191
- var _a, _b;
193
+ var _a, _b, _c;
192
194
  const { req } = ctx;
193
195
  const parsedUrl = (0, import_url.parse)(req.url);
194
196
  const appName = (_a = import_qs.default.parse(parsedUrl.query)) == null ? void 0 : _a.__appName;
195
197
  const apiBasePath = normalizeBasePath(import_node_process.default.env.API_BASE_PATH || "/api");
196
198
  const appPathPrefix = `${apiBasePath}/__app/`;
199
+ const appPublicPath = (0, import_utils3.resolvePublicPath)(import_node_process.default.env.APP_PUBLIC_PATH || "/");
200
+ const portalAppsPathPrefix = `${appPublicPath.replace(/\/$/, "")}/${import_utils3.PORTAL_CLIENT_PREFIX}/apps/`;
197
201
  if (req.headers["x-app"]) {
198
202
  ctx.resolvedAppName = req.headers["x-app"];
199
203
  }
200
204
  if (appName) {
201
205
  ctx.resolvedAppName = appName;
202
206
  }
203
- if ((_b = parsedUrl.pathname) == null ? void 0 : _b.startsWith(appPathPrefix)) {
207
+ if ((_b = parsedUrl.pathname) == null ? void 0 : _b.startsWith(portalAppsPathPrefix)) {
208
+ const restPath = parsedUrl.pathname.slice(portalAppsPathPrefix.length);
209
+ const [pathAppName] = restPath.split("/");
210
+ if (pathAppName) {
211
+ ctx.resolvedAppName = (0, import_utils3.normalizePortalAppName)(pathAppName);
212
+ }
213
+ }
214
+ if ((_c = parsedUrl.pathname) == null ? void 0 : _c.startsWith(appPathPrefix)) {
204
215
  const restPath = parsedUrl.pathname.slice(appPathPrefix.length);
205
216
  const [pathAppName, ...segments] = restPath.split("/");
206
217
  if (pathAppName) {
@@ -292,6 +303,156 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
292
303
  getAppPublicPath() {
293
304
  return (0, import_utils3.resolvePublicPath)(import_node_process.default.env.APP_PUBLIC_PATH || "/");
294
305
  }
306
+ getSettingsPublicPath() {
307
+ return (0, import_utils3.resolveSettingsPublicPath)(import_node_process.default.env.APP_PUBLIC_PATH || "/");
308
+ }
309
+ getPathWithinAppPublicPath(pathname) {
310
+ const appPublicPath = this.getAppPublicPath();
311
+ if (appPublicPath === "/") {
312
+ return pathname;
313
+ }
314
+ const appPublicPathWithoutSlash = appPublicPath.slice(0, -1);
315
+ if (pathname === appPublicPathWithoutSlash) {
316
+ return "/";
317
+ }
318
+ if (!pathname.startsWith(appPublicPath)) {
319
+ return null;
320
+ }
321
+ return pathname.slice(appPublicPath.length - 1);
322
+ }
323
+ isSettingsRequest(pathname) {
324
+ const appPath = this.getPathWithinAppPublicPath(pathname);
325
+ if (!appPath) {
326
+ return false;
327
+ }
328
+ return /^\/settings(?:\/|$)/.test(appPath);
329
+ }
330
+ isSettingsIndexRequest(pathname) {
331
+ if (!this.isSettingsRequest(pathname)) {
332
+ return false;
333
+ }
334
+ if (pathname.endsWith("/index.html")) {
335
+ return true;
336
+ }
337
+ return !(0, import_path.extname)(pathname);
338
+ }
339
+ isSettingsAssetsRequest(pathname) {
340
+ const appPath = this.getPathWithinAppPublicPath(pathname);
341
+ return appPath ? /^\/settings\/assets\//.test(appPath) : false;
342
+ }
343
+ resolveLegacyV2SettingsRedirect(pathname) {
344
+ const appPath = this.getPathWithinAppPublicPath(pathname);
345
+ if (!appPath) {
346
+ return null;
347
+ }
348
+ const modernPrefix = (0, import_utils3.normalizeModernClientPrefix)(import_node_process.default.env.APP_MODERN_CLIENT_PREFIX);
349
+ const escapedModernPrefix = modernPrefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
350
+ const match = appPath.match(new RegExp(`^/${escapedModernPrefix}((?:/(?:apps|_app)/[^/]+)?)(/admin(?:/.*)?)$`));
351
+ if (!match) {
352
+ return null;
353
+ }
354
+ const appScope = match[1] || "";
355
+ const legacyPath = match[2];
356
+ const mappings = [
357
+ {
358
+ from: "/admin/settings/mail/oauth2",
359
+ to: "/admin/settings/mail/oauth2"
360
+ },
361
+ {
362
+ from: "/admin/workflow/executions",
363
+ to: "/settings/workflow/executions"
364
+ },
365
+ {
366
+ from: "/admin/workflow/workflows",
367
+ to: "/settings/workflow/workflows"
368
+ },
369
+ {
370
+ from: "/admin/settings",
371
+ to: "/settings"
372
+ }
373
+ ];
374
+ for (const { from, to } of mappings) {
375
+ if (legacyPath !== from && !legacyPath.startsWith(`${from}/`)) {
376
+ continue;
377
+ }
378
+ const appPublicPath = this.getAppPublicPath().replace(/\/$/, "");
379
+ const targetPath = from === "/admin/settings/mail/oauth2" ? `${appScope}${to}` : appScope ? `/settings${appScope}${to.replace(/^\/settings(?=\/|$)/, "")}` : to;
380
+ return `${appPublicPath}${targetPath}${legacyPath.slice(from.length)}`;
381
+ }
382
+ return null;
383
+ }
384
+ getPortalRootPublicPath() {
385
+ return `${this.getAppPublicPath().replace(/\/$/, "")}/${import_utils3.PORTAL_CLIENT_PREFIX}/`;
386
+ }
387
+ getPortalAppPublicPath(appName) {
388
+ if (appName === import_utils3.DEFAULT_PORTAL_APP_NAME) {
389
+ return this.getPortalRootPublicPath();
390
+ }
391
+ return `${this.getPortalRootPublicPath()}apps/${(0, import_utils3.normalizePortalAppName)(appName)}/`;
392
+ }
393
+ resolvePortalRootEntryRedirect(pathname) {
394
+ const portalRootPublicPath = this.getPortalRootPublicPath();
395
+ const v2PublicPath = this.getV2PublicPath();
396
+ if (v2PublicPath === portalRootPublicPath) {
397
+ return null;
398
+ }
399
+ if (pathname === portalRootPublicPath || pathname === portalRootPublicPath.slice(0, -1)) {
400
+ return v2PublicPath;
401
+ }
402
+ const portalAppsPublicPath = `${portalRootPublicPath}apps/`;
403
+ if (!pathname.startsWith(portalAppsPublicPath)) {
404
+ return null;
405
+ }
406
+ const match = /^([A-Za-z0-9_-]+)\/?$/.exec(pathname.slice(portalAppsPublicPath.length));
407
+ return match ? `${v2PublicPath}apps/${match[1]}/` : null;
408
+ }
409
+ getPortalMatch(pathname) {
410
+ const portalRootPublicPath = this.getPortalRootPublicPath();
411
+ if (!pathname.startsWith(portalRootPublicPath)) {
412
+ return null;
413
+ }
414
+ let appName = import_utils3.DEFAULT_PORTAL_APP_NAME;
415
+ let publicRoot = portalRootPublicPath;
416
+ let restPath = pathname.slice(portalRootPublicPath.length).replace(/^\/+/, "");
417
+ const [firstSegment, secondSegment, ...remainingSegments] = restPath.split("/");
418
+ if (firstSegment === "apps") {
419
+ if (!secondSegment || !/^[A-Za-z0-9_-]+$/.test(secondSegment)) {
420
+ return null;
421
+ }
422
+ appName = (0, import_utils3.normalizePortalAppName)(secondSegment);
423
+ publicRoot = this.getPortalAppPublicPath(appName);
424
+ if (!pathname.startsWith(publicRoot)) {
425
+ return null;
426
+ }
427
+ restPath = remainingSegments.join("/").replace(/^\/+/, "");
428
+ }
429
+ const [portalName] = restPath.split("/");
430
+ if (!portalName || !/^[A-Za-z0-9_-]+$/.test(portalName)) {
431
+ return null;
432
+ }
433
+ return {
434
+ appName,
435
+ portalName,
436
+ publicPath: `${publicRoot}${portalName}/`
437
+ };
438
+ }
439
+ isPortalIndexRequest(pathname, portalPublicPath) {
440
+ if (pathname === portalPublicPath || pathname === portalPublicPath.slice(0, -1) || pathname === `${portalPublicPath}index.html`) {
441
+ return true;
442
+ }
443
+ return !(0, import_path.extname)(pathname);
444
+ }
445
+ getPortalDistRoot(portalMatch) {
446
+ const scopedRoot = (0, import_utils.storagePathJoin)("portals", portalMatch.appName, portalMatch.portalName, "dist");
447
+ if (portalMatch.appName !== import_utils3.DEFAULT_PORTAL_APP_NAME) {
448
+ return scopedRoot;
449
+ }
450
+ const legacyRoot = (0, import_utils.storagePathJoin)("portals", portalMatch.portalName, "dist");
451
+ if (!import_fs.default.existsSync((0, import_path.resolve)(scopedRoot, "index.html")) && import_fs.default.existsSync((0, import_path.resolve)(legacyRoot, "index.html"))) {
452
+ return legacyRoot;
453
+ }
454
+ return scopedRoot;
455
+ }
295
456
  isV2Request(pathname) {
296
457
  const v2PublicPath = this.getV2PublicPath();
297
458
  return pathname === v2PublicPath.slice(0, -1) || pathname.startsWith(v2PublicPath);
@@ -358,6 +519,57 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
358
519
  const html = (0, import_utils3.rewriteV2AssetPublicPath)(template, this.getV2AssetPublicPath());
359
520
  return (0, import_utils3.injectRuntimeScript)(html, this.getV2RuntimeConfigScript());
360
521
  }
522
+ getSettingsRuntimeConfig() {
523
+ return {
524
+ __nocobase_public_path__: this.getAppPublicPath(),
525
+ __nocobase_modern_client_prefix__: (0, import_utils3.normalizeModernClientPrefix)(import_node_process.default.env.APP_MODERN_CLIENT_PREFIX),
526
+ __webpack_public_path__: import_node_process.default.env.CDN_BASE_URL ? `${import_node_process.default.env.CDN_BASE_URL.replace(/\/+$/, "")}/` : "",
527
+ __nocobase_api_base_url__: import_node_process.default.env.API_BASE_URL || import_node_process.default.env.API_BASE_PATH,
528
+ __nocobase_api_client_storage_prefix__: import_node_process.default.env.API_CLIENT_STORAGE_PREFIX,
529
+ __nocobase_api_client_storage_type__: import_node_process.default.env.API_CLIENT_STORAGE_TYPE,
530
+ __nocobase_api_client_share_token__: import_node_process.default.env.API_CLIENT_SHARE_TOKEN === "true",
531
+ __nocobase_ws_url__: import_node_process.default.env.WEBSOCKET_URL || "",
532
+ __nocobase_ws_path__: import_node_process.default.env.WS_PATH,
533
+ __nocobase_app_dev__: import_node_process.default.env.NOCOBASE_APP_DEV === "true",
534
+ __esm_cdn_base_url__: import_node_process.default.env.ESM_CDN_BASE_URL || "https://esm.sh",
535
+ __esm_cdn_suffix__: import_node_process.default.env.ESM_CDN_SUFFIX || ""
536
+ };
537
+ }
538
+ getSettingsRuntimeConfigScript() {
539
+ const scriptContent = Object.entries(this.getSettingsRuntimeConfig()).map(([key, value]) => `window['${key}'] = ${JSON.stringify(value)};`).join("\n");
540
+ return `<script>${scriptContent}</script>`;
541
+ }
542
+ getSettingsAssetPublicPath() {
543
+ if (import_node_process.default.env.CDN_BASE_URL) {
544
+ return `${import_node_process.default.env.CDN_BASE_URL.replace(/\/+$/, "")}/${import_utils3.SETTINGS_CLIENT_DIST_DIR}/`;
545
+ }
546
+ return this.getSettingsPublicPath();
547
+ }
548
+ getSettingsIndexTemplate() {
549
+ const file = `${import_node_process.default.env.APP_PACKAGE_ROOT}/dist/client/${import_utils3.SETTINGS_CLIENT_DIST_DIR}/index.html`;
550
+ if (!import_fs.default.existsSync(file)) {
551
+ return null;
552
+ }
553
+ const stat = import_fs.default.statSync(file);
554
+ if (this.settingsIndexTemplateCache && this.settingsIndexTemplateCache.file === file && this.settingsIndexTemplateCache.mtimeMs === stat.mtimeMs) {
555
+ return this.settingsIndexTemplateCache.html;
556
+ }
557
+ const html = import_fs.default.readFileSync(file, "utf-8");
558
+ this.settingsIndexTemplateCache = {
559
+ file,
560
+ mtimeMs: stat.mtimeMs,
561
+ html
562
+ };
563
+ return html;
564
+ }
565
+ renderSettingsIndexHtml() {
566
+ const template = this.getSettingsIndexTemplate();
567
+ if (!template) {
568
+ return null;
569
+ }
570
+ const html = (0, import_utils3.rewriteSettingsAssetPublicPath)(template, this.getSettingsAssetPublicPath());
571
+ return (0, import_utils3.injectRuntimeScript)(html, this.getSettingsRuntimeConfigScript());
572
+ }
361
573
  async requestHandler(req, res) {
362
574
  const { pathname, search } = (0, import_url.parse)(req.url);
363
575
  const { PLUGIN_STATICS_PATH } = import_node_process.default.env;
@@ -373,6 +585,20 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
373
585
  res.end();
374
586
  return;
375
587
  }
588
+ const settingsRedirect = this.resolveLegacyV2SettingsRedirect(pathname);
589
+ if (settingsRedirect) {
590
+ res.statusCode = 302;
591
+ res.setHeader("Location", `${settingsRedirect}${search || ""}`);
592
+ res.end();
593
+ return;
594
+ }
595
+ const portalRootEntryRedirect = this.resolvePortalRootEntryRedirect(pathname);
596
+ if (portalRootEntryRedirect) {
597
+ res.statusCode = 302;
598
+ res.setHeader("Location", `${portalRootEntryRedirect}${search || ""}`);
599
+ res.end();
600
+ return;
601
+ }
376
602
  const supervisor = import_app_supervisor.AppSupervisor.getInstance();
377
603
  let handleApp = "main";
378
604
  try {
@@ -440,6 +666,70 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
440
666
  }
441
667
  const isFilesRequest = Boolean(getFileAccessRestPath(pathname, APP_PUBLIC_PATH));
442
668
  if (!pathname.startsWith(import_node_process.default.env.API_BASE_PATH) && !isFilesRequest) {
669
+ if (this.isSettingsRequest(pathname)) {
670
+ if (handleApp !== "main") {
671
+ const isProxy = await this.proxyRequestToSubApp(supervisor, handleApp, req, res);
672
+ if (isProxy) {
673
+ return;
674
+ }
675
+ }
676
+ if (this.isSettingsIndexRequest(pathname)) {
677
+ const settingsHtml = this.renderSettingsIndexHtml();
678
+ if (settingsHtml) {
679
+ res.setHeader("Cache-Control", "no-store");
680
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
681
+ res.end(settingsHtml);
682
+ return;
683
+ }
684
+ }
685
+ if (this.isSettingsAssetsRequest(pathname)) {
686
+ res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
687
+ }
688
+ req.url = req.url.substring(APP_PUBLIC_PATH.length - 1);
689
+ await compress(req, res);
690
+ return (0, import_serve_handler.default)(req, res, {
691
+ public: `${import_node_process.default.env.APP_PACKAGE_ROOT}/dist/client`
692
+ });
693
+ }
694
+ const portalMatch = this.getPortalMatch(pathname);
695
+ if (portalMatch) {
696
+ if (handleApp !== "main" && handleApp !== portalMatch.appName) {
697
+ const isProxy = await this.proxyRequestToSubApp(supervisor, handleApp, req, res);
698
+ if (isProxy) {
699
+ return;
700
+ }
701
+ }
702
+ const portalDistRoot = this.getPortalDistRoot(portalMatch);
703
+ const portalIndex = (0, import_path.resolve)(portalDistRoot, "index.html");
704
+ if (!import_fs.default.existsSync(portalIndex)) {
705
+ res.statusCode = 404;
706
+ res.end();
707
+ return;
708
+ }
709
+ if (!pathname.startsWith(portalMatch.publicPath)) {
710
+ res.statusCode = 302;
711
+ res.setHeader("Location", `${portalMatch.publicPath}${search || ""}`);
712
+ res.end();
713
+ return;
714
+ }
715
+ if (this.isPortalIndexRequest(pathname, portalMatch.publicPath)) {
716
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
717
+ res.end(import_fs.default.readFileSync(portalIndex, "utf-8"));
718
+ return;
719
+ }
720
+ req.url = req.url.substring(portalMatch.publicPath.length - 1);
721
+ await compress(req, res);
722
+ return (0, import_serve_handler.default)(req, res, {
723
+ public: portalDistRoot,
724
+ directoryListing: false
725
+ });
726
+ }
727
+ const portalRootPublicPath = this.getPortalRootPublicPath();
728
+ if (pathname === portalRootPublicPath.slice(0, -1) || pathname.startsWith(portalRootPublicPath)) {
729
+ res.statusCode = 404;
730
+ res.end();
731
+ return;
732
+ }
443
733
  if (this.isV2Request(pathname)) {
444
734
  if (handleApp !== "main") {
445
735
  const isProxy = await this.proxyRequestToSubApp(supervisor, handleApp, req, res);
@@ -10,10 +10,19 @@
10
10
  import { IncomingMessage } from 'http';
11
11
  import { IncomingRequest } from '.';
12
12
  export declare const MODERN_CLIENT_DIST_DIR = "v";
13
+ export declare const SETTINGS_CLIENT_DIST_DIR = "settings";
14
+ export declare const PORTAL_CLIENT_PREFIX = "x";
15
+ export declare const DEFAULT_PORTAL_APP_NAME = "main";
16
+ export declare const DEFAULT_PORTAL_NAME = "admin";
13
17
  export declare function resolvePublicPath(appPublicPath?: string): string;
14
18
  export declare function normalizeModernClientPrefix(value?: string): string;
15
19
  export declare function resolveV2PublicPath(appPublicPath?: string): string;
20
+ export declare function resolveSettingsPublicPath(appPublicPath?: string): string;
21
+ export declare function normalizePortalName(value?: string): string;
22
+ export declare function normalizePortalAppName(value?: string): string;
23
+ export declare function resolvePortalPublicPath(portalName: string, appPublicPath?: string): string;
16
24
  export declare function rewriteV2AssetPublicPath(html: string, assetPublicPath: string): string;
25
+ export declare function rewriteSettingsAssetPublicPath(html: string, assetPublicPath: string): string;
17
26
  export declare function injectRuntimeScript(html: string, runtimeScript: string): string;
18
27
  export declare function getHost(req: IncomingMessage | IncomingRequest): any;
19
28
  export declare function getHostname(req: IncomingMessage | IncomingRequest): any;
@@ -27,17 +27,30 @@ var __copyProps = (to, from, except, desc) => {
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
  var utils_exports = {};
29
29
  __export(utils_exports, {
30
+ DEFAULT_PORTAL_APP_NAME: () => DEFAULT_PORTAL_APP_NAME,
31
+ DEFAULT_PORTAL_NAME: () => DEFAULT_PORTAL_NAME,
30
32
  MODERN_CLIENT_DIST_DIR: () => MODERN_CLIENT_DIST_DIR,
33
+ PORTAL_CLIENT_PREFIX: () => PORTAL_CLIENT_PREFIX,
34
+ SETTINGS_CLIENT_DIST_DIR: () => SETTINGS_CLIENT_DIST_DIR,
31
35
  getHost: () => getHost,
32
36
  getHostname: () => getHostname,
33
37
  injectRuntimeScript: () => injectRuntimeScript,
34
38
  normalizeModernClientPrefix: () => normalizeModernClientPrefix,
39
+ normalizePortalAppName: () => normalizePortalAppName,
40
+ normalizePortalName: () => normalizePortalName,
41
+ resolvePortalPublicPath: () => resolvePortalPublicPath,
35
42
  resolvePublicPath: () => resolvePublicPath,
43
+ resolveSettingsPublicPath: () => resolveSettingsPublicPath,
36
44
  resolveV2PublicPath: () => resolveV2PublicPath,
45
+ rewriteSettingsAssetPublicPath: () => rewriteSettingsAssetPublicPath,
37
46
  rewriteV2AssetPublicPath: () => rewriteV2AssetPublicPath
38
47
  });
39
48
  module.exports = __toCommonJS(utils_exports);
40
49
  const MODERN_CLIENT_DIST_DIR = "v";
50
+ const SETTINGS_CLIENT_DIST_DIR = "settings";
51
+ const PORTAL_CLIENT_PREFIX = "x";
52
+ const DEFAULT_PORTAL_APP_NAME = "main";
53
+ const DEFAULT_PORTAL_NAME = "admin";
41
54
  function resolvePublicPath(appPublicPath = "/") {
42
55
  const normalized = String(appPublicPath || "/").trim() || "/";
43
56
  const withLeadingSlash = normalized.startsWith("/") ? normalized : `/${normalized}`;
@@ -46,7 +59,11 @@ function resolvePublicPath(appPublicPath = "/") {
46
59
  __name(resolvePublicPath, "resolvePublicPath");
47
60
  function normalizeModernClientPrefix(value) {
48
61
  const segment = String(value || "").trim().replace(/^\/+|\/+$/g, "");
49
- return segment || MODERN_CLIENT_DIST_DIR;
62
+ const normalized = segment || MODERN_CLIENT_DIST_DIR;
63
+ if (normalized === SETTINGS_CLIENT_DIST_DIR) {
64
+ throw new Error('APP_MODERN_CLIENT_PREFIX "settings" is reserved for the standalone Settings application.');
65
+ }
66
+ return normalized;
50
67
  }
51
68
  __name(normalizeModernClientPrefix, "normalizeModernClientPrefix");
52
69
  function resolveV2PublicPath(appPublicPath = "/") {
@@ -55,6 +72,26 @@ function resolveV2PublicPath(appPublicPath = "/") {
55
72
  return `${publicPath.replace(/\/$/, "")}/${prefix}/`;
56
73
  }
57
74
  __name(resolveV2PublicPath, "resolveV2PublicPath");
75
+ function resolveSettingsPublicPath(appPublicPath = "/") {
76
+ const publicPath = resolvePublicPath(appPublicPath);
77
+ return `${publicPath.replace(/\/$/, "")}/${SETTINGS_CLIENT_DIST_DIR}/`;
78
+ }
79
+ __name(resolveSettingsPublicPath, "resolveSettingsPublicPath");
80
+ function normalizePortalName(value) {
81
+ const segment = String(value || "").trim().replace(/^\/+|\/+$/g, "");
82
+ return segment || DEFAULT_PORTAL_NAME;
83
+ }
84
+ __name(normalizePortalName, "normalizePortalName");
85
+ function normalizePortalAppName(value) {
86
+ const segment = String(value || "").trim().replace(/^\/+|\/+$/g, "");
87
+ return segment || DEFAULT_PORTAL_APP_NAME;
88
+ }
89
+ __name(normalizePortalAppName, "normalizePortalAppName");
90
+ function resolvePortalPublicPath(portalName, appPublicPath = "/") {
91
+ const publicPath = resolvePublicPath(appPublicPath);
92
+ return `${publicPath.replace(/\/$/, "")}/${PORTAL_CLIENT_PREFIX}/${normalizePortalName(portalName)}/`;
93
+ }
94
+ __name(resolvePortalPublicPath, "resolvePortalPublicPath");
58
95
  function ensureTrailingSlash(value) {
59
96
  return value.endsWith("/") ? value : `${value}/`;
60
97
  }
@@ -69,6 +106,16 @@ function rewriteV2AssetPublicPath(html, assetPublicPath) {
69
106
  return html.replace(sentinelPattern, `$1${normalizedAssetPublicPath}`);
70
107
  }
71
108
  __name(rewriteV2AssetPublicPath, "rewriteV2AssetPublicPath");
109
+ function rewriteSettingsAssetPublicPath(html, assetPublicPath) {
110
+ const normalizedAssetPublicPath = ensureTrailingSlash(assetPublicPath);
111
+ const sentinel = `/${SETTINGS_CLIENT_DIST_DIR}/`;
112
+ if (normalizedAssetPublicPath === sentinel) {
113
+ return html;
114
+ }
115
+ const sentinelPattern = new RegExp(`((?:src|href)=["'])${sentinel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`, "g");
116
+ return html.replace(sentinelPattern, `$1${normalizedAssetPublicPath}`);
117
+ }
118
+ __name(rewriteSettingsAssetPublicPath, "rewriteSettingsAssetPublicPath");
72
119
  function injectRuntimeScript(html, runtimeScript) {
73
120
  const browserCheckerScriptMatch = html.match(/<script\b[^>]*browser-checker\.js[^>]*><\/script>/i);
74
121
  if (browserCheckerScriptMatch == null ? void 0 : browserCheckerScriptMatch[0]) {
@@ -117,12 +164,21 @@ function getHostname(req) {
117
164
  __name(getHostname, "getHostname");
118
165
  // Annotate the CommonJS export names for ESM import in node:
119
166
  0 && (module.exports = {
167
+ DEFAULT_PORTAL_APP_NAME,
168
+ DEFAULT_PORTAL_NAME,
120
169
  MODERN_CLIENT_DIST_DIR,
170
+ PORTAL_CLIENT_PREFIX,
171
+ SETTINGS_CLIENT_DIST_DIR,
121
172
  getHost,
122
173
  getHostname,
123
174
  injectRuntimeScript,
124
175
  normalizeModernClientPrefix,
176
+ normalizePortalAppName,
177
+ normalizePortalName,
178
+ resolvePortalPublicPath,
125
179
  resolvePublicPath,
180
+ resolveSettingsPublicPath,
126
181
  resolveV2PublicPath,
182
+ rewriteSettingsAssetPublicPath,
127
183
  rewriteV2AssetPublicPath
128
184
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "2.3.0-beta.5",
3
+ "version": "2.4.0-alpha.1",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -10,21 +10,21 @@
10
10
  "@koa/cors": "^5.0.0",
11
11
  "@koa/multer": "^3.1.0",
12
12
  "@koa/router": "^13.1.0",
13
- "@nocobase/acl": "2.3.0-beta.5",
14
- "@nocobase/actions": "2.3.0-beta.5",
15
- "@nocobase/ai": "2.3.0-beta.5",
16
- "@nocobase/auth": "2.3.0-beta.5",
17
- "@nocobase/cache": "2.3.0-beta.5",
18
- "@nocobase/data-source-manager": "2.3.0-beta.5",
19
- "@nocobase/database": "2.3.0-beta.5",
20
- "@nocobase/evaluators": "2.3.0-beta.5",
21
- "@nocobase/lock-manager": "2.3.0-beta.5",
22
- "@nocobase/logger": "2.3.0-beta.5",
23
- "@nocobase/resourcer": "2.3.0-beta.5",
24
- "@nocobase/sdk": "2.3.0-beta.5",
25
- "@nocobase/snowflake-id": "2.3.0-beta.5",
26
- "@nocobase/telemetry": "2.3.0-beta.5",
27
- "@nocobase/utils": "2.3.0-beta.5",
13
+ "@nocobase/acl": "2.4.0-alpha.1",
14
+ "@nocobase/actions": "2.4.0-alpha.1",
15
+ "@nocobase/ai": "2.4.0-alpha.1",
16
+ "@nocobase/auth": "2.4.0-alpha.1",
17
+ "@nocobase/cache": "2.4.0-alpha.1",
18
+ "@nocobase/data-source-manager": "2.4.0-alpha.1",
19
+ "@nocobase/database": "2.4.0-alpha.1",
20
+ "@nocobase/evaluators": "2.4.0-alpha.1",
21
+ "@nocobase/lock-manager": "2.4.0-alpha.1",
22
+ "@nocobase/logger": "2.4.0-alpha.1",
23
+ "@nocobase/resourcer": "2.4.0-alpha.1",
24
+ "@nocobase/sdk": "2.4.0-alpha.1",
25
+ "@nocobase/snowflake-id": "2.4.0-alpha.1",
26
+ "@nocobase/telemetry": "2.4.0-alpha.1",
27
+ "@nocobase/utils": "2.4.0-alpha.1",
28
28
  "@types/decompress": "4.2.7",
29
29
  "@types/ini": "^1.3.31",
30
30
  "@types/koa-send": "^4.1.3",
@@ -61,5 +61,5 @@
61
61
  "@types/serve-handler": "^6.1.1",
62
62
  "@types/ws": "^8.5.5"
63
63
  },
64
- "gitHead": "7047516aba0d14965ddf457b64587103a871b923"
64
+ "gitHead": "82ecd3aed067e4cc98c32e7a0039b6e55cee76a7"
65
65
  }