@nocobase/server 2.1.0-beta.15 → 2.1.0-beta.16
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/lib/acl/available-action.js +1 -1
- package/lib/aes-encryptor.js +3 -2
- package/lib/ai/create-docs-index.js +2 -1
- package/lib/app-supervisor/app-options-factory.d.ts +1 -0
- package/lib/audit-manager/index.d.ts +2 -0
- package/lib/audit-manager/index.js +5 -2
- package/lib/commands/create-migration.js +1 -1
- package/lib/commands/pm.js +7 -0
- package/lib/commands/start.js +2 -2
- package/lib/event-queue.js +1 -1
- package/lib/gateway/index.d.ts +13 -3
- package/lib/gateway/index.js +137 -15
- package/lib/gateway/utils.d.ts +17 -0
- package/lib/gateway/utils.js +115 -0
- package/lib/plugin-manager/deps.js +2 -1
- package/lib/plugin-manager/options/resource.d.ts +11 -1
- package/lib/plugin-manager/options/resource.js +151 -65
- package/lib/plugin-manager/plugin-manager.d.ts +6 -2
- package/lib/plugin-manager/plugin-manager.js +22 -3
- package/lib/plugin-manager/utils.d.ts +7 -1
- package/lib/plugin-manager/utils.js +32 -8
- package/lib/plugin.js +33 -1
- package/lib/swagger/app.d.ts +102 -0
- package/lib/swagger/app.js +124 -0
- package/lib/swagger/base.d.ts +244 -0
- package/lib/swagger/base.js +292 -0
- package/lib/swagger/collections.d.ts +996 -0
- package/lib/swagger/collections.js +1264 -0
- package/lib/swagger/index.d.ts +1774 -0
- package/lib/swagger/index.js +70 -0
- package/lib/swagger/pm.d.ts +462 -0
- package/lib/swagger/pm.js +422 -0
- package/package.json +17 -17
- package/lib/swagger/index.json +0 -1569
package/lib/aes-encryptor.js
CHANGED
|
@@ -44,6 +44,7 @@ module.exports = __toCommonJS(aes_encryptor_exports);
|
|
|
44
44
|
var import_crypto = __toESM(require("crypto"));
|
|
45
45
|
var import_fs_extra = __toESM(require("fs-extra"));
|
|
46
46
|
var import_path = __toESM(require("path"));
|
|
47
|
+
var import_utils = require("@nocobase/utils");
|
|
47
48
|
const _AesEncryptor = class _AesEncryptor {
|
|
48
49
|
key;
|
|
49
50
|
constructor(key) {
|
|
@@ -99,12 +100,12 @@ const _AesEncryptor = class _AesEncryptor {
|
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
static async getKeyPath(appName) {
|
|
102
|
-
const appKeyPath =
|
|
103
|
+
const appKeyPath = (0, import_utils.storagePathJoin)("apps", appName, "aes_key.dat");
|
|
103
104
|
const appKeyExists = await import_fs_extra.default.exists(appKeyPath);
|
|
104
105
|
if (appKeyExists) {
|
|
105
106
|
return appKeyPath;
|
|
106
107
|
}
|
|
107
|
-
const envKeyPath =
|
|
108
|
+
const envKeyPath = (0, import_utils.storagePathJoin)("environment-variables", appName, "aes_key.dat");
|
|
108
109
|
const envKeyExists = await import_fs_extra.default.exists(envKeyPath);
|
|
109
110
|
if (envKeyExists) {
|
|
110
111
|
return envKeyPath;
|
|
@@ -43,10 +43,11 @@ module.exports = __toCommonJS(create_docs_index_exports);
|
|
|
43
43
|
var import_fast_glob = __toESM(require("fast-glob"));
|
|
44
44
|
var import_fs_extra = __toESM(require("fs-extra"));
|
|
45
45
|
var import_path = __toESM(require("path"));
|
|
46
|
+
var import_utils = require("@nocobase/utils");
|
|
46
47
|
var import_ai = require("@nocobase/ai");
|
|
47
48
|
var import_findPackageNames = require("../plugin-manager/findPackageNames");
|
|
48
49
|
var import_plugin_manager = require("../plugin-manager");
|
|
49
|
-
const DOCS_STORAGE_DIR =
|
|
50
|
+
const DOCS_STORAGE_DIR = (0, import_utils.storagePathJoin)("ai", "docs");
|
|
50
51
|
const REFERENCE_START = "<!-- docs:references:start -->";
|
|
51
52
|
const REFERENCE_END = "<!-- docs:references:end -->";
|
|
52
53
|
const SPLIT_REFERENCE_START = "<!-- docs:splits:start -->";
|
|
@@ -16,6 +16,7 @@ export declare const appOptionsFactory: (appName: string, mainApp: Application,
|
|
|
16
16
|
migrator?: any;
|
|
17
17
|
usingBigIntForId?: boolean;
|
|
18
18
|
underscored?: boolean;
|
|
19
|
+
rawTimezone?: string;
|
|
19
20
|
logger?: import("@nocobase/logger/lib/logger").Logger | import("@nocobase/logger/lib/logger").LoggerOptions;
|
|
20
21
|
customHooks?: any;
|
|
21
22
|
instanceId?: string;
|
|
@@ -12,6 +12,7 @@ export interface AuditLog {
|
|
|
12
12
|
dataSource: string;
|
|
13
13
|
resource: string;
|
|
14
14
|
action: string;
|
|
15
|
+
requestSource?: string;
|
|
15
16
|
sourceCollection?: string;
|
|
16
17
|
sourceRecordUK?: string;
|
|
17
18
|
targetCollection?: string;
|
|
@@ -102,6 +103,7 @@ export declare class AuditManager {
|
|
|
102
103
|
'x-authenticator': any;
|
|
103
104
|
'x-locale': any;
|
|
104
105
|
'x-timezone': any;
|
|
106
|
+
'x-request-source': any;
|
|
105
107
|
};
|
|
106
108
|
};
|
|
107
109
|
response: {
|
|
@@ -41,6 +41,7 @@ __export(audit_manager_exports, {
|
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(audit_manager_exports);
|
|
43
43
|
var import_stream = __toESM(require("stream"));
|
|
44
|
+
const REQUEST_SOURCE_HEADER = "x-request-source";
|
|
44
45
|
function isStream(obj) {
|
|
45
46
|
return obj instanceof import_stream.default.Readable || obj instanceof import_stream.default.Writable || obj instanceof import_stream.default.Duplex || obj instanceof import_stream.default.Transform;
|
|
46
47
|
}
|
|
@@ -201,7 +202,7 @@ const _AuditManager = class _AuditManager {
|
|
|
201
202
|
return null;
|
|
202
203
|
}
|
|
203
204
|
async getDefaultMetaData(ctx) {
|
|
204
|
-
var _a, _b, _c;
|
|
205
|
+
var _a, _b, _c, _d;
|
|
205
206
|
let body = null;
|
|
206
207
|
if (ctx.body) {
|
|
207
208
|
if (!Buffer.isBuffer(ctx.body) && !isStream(ctx.body)) {
|
|
@@ -217,7 +218,8 @@ const _AuditManager = class _AuditManager {
|
|
|
217
218
|
headers: {
|
|
218
219
|
"x-authenticator": (_a = ctx.request) == null ? void 0 : _a.headers["x-authenticator"],
|
|
219
220
|
"x-locale": (_b = ctx.request) == null ? void 0 : _b.headers["x-locale"],
|
|
220
|
-
"x-timezone": (_c = ctx.request) == null ? void 0 : _c.headers["x-timezone"]
|
|
221
|
+
"x-timezone": (_c = ctx.request) == null ? void 0 : _c.headers["x-timezone"],
|
|
222
|
+
"x-request-source": (_d = ctx.request) == null ? void 0 : _d.headers[REQUEST_SOURCE_HEADER]
|
|
221
223
|
}
|
|
222
224
|
},
|
|
223
225
|
response: {
|
|
@@ -241,6 +243,7 @@ const _AuditManager = class _AuditManager {
|
|
|
241
243
|
dataSource: ctx.request.header["x-data-source"] || "main",
|
|
242
244
|
resource: resourceName,
|
|
243
245
|
action: ctx.action.actionName,
|
|
246
|
+
requestSource: ctx.request.header[REQUEST_SOURCE_HEADER],
|
|
244
247
|
userId: (_b = (_a = ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.id,
|
|
245
248
|
roleName: (_c = ctx.state) == null ? void 0 : _c.currentRole,
|
|
246
249
|
ip: ips.length > 0 ? ips[0] : ctx.request.ip,
|
|
@@ -76,6 +76,6 @@ export default class extends Migration {
|
|
|
76
76
|
`;
|
|
77
77
|
await import_fs.default.promises.mkdir((0, import_path.dirname)(filename), { recursive: true });
|
|
78
78
|
await import_fs.default.promises.writeFile(filename, data, "utf8");
|
|
79
|
-
|
|
79
|
+
console.log(`migration file in ${filename}`);
|
|
80
80
|
});
|
|
81
81
|
}, "default");
|
package/lib/commands/pm.js
CHANGED
|
@@ -32,9 +32,16 @@ __export(pm_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(pm_exports);
|
|
33
33
|
var import_app_supervisor = require("../app-supervisor");
|
|
34
34
|
var import_plugin_command_error = require("../errors/plugin-command-error");
|
|
35
|
+
var import_utils = require("../plugin-manager/utils");
|
|
35
36
|
/* istanbul ignore file -- @preserve */
|
|
36
37
|
var pm_default = /* @__PURE__ */ __name((app) => {
|
|
37
38
|
const pm = app.command("pm");
|
|
39
|
+
pm.command("list").action(async () => {
|
|
40
|
+
const items = await (0, import_utils.pmListSummary)(app);
|
|
41
|
+
console.log("--- BEGIN_PLUGIN_LIST_JSON ---");
|
|
42
|
+
console.log(JSON.stringify(items));
|
|
43
|
+
console.log("--- END_PLUGIN_LIST_JSON ---");
|
|
44
|
+
});
|
|
38
45
|
pm.command("create").argument("plugin").option("--force-recreate").action(async (plugin, options) => {
|
|
39
46
|
await app.pm.create(plugin, options);
|
|
40
47
|
});
|
package/lib/commands/start.js
CHANGED
|
@@ -41,14 +41,14 @@ __export(start_exports, {
|
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(start_exports);
|
|
43
43
|
var import_fs_extra = __toESM(require("fs-extra"));
|
|
44
|
-
var
|
|
44
|
+
var import_utils = require("@nocobase/utils");
|
|
45
45
|
var import_create_docs_index = require("../ai/create-docs-index");
|
|
46
46
|
var import_application_not_install = require("../errors/application-not-install");
|
|
47
47
|
/* istanbul ignore file -- @preserve */
|
|
48
48
|
var start_default = /* @__PURE__ */ __name((app) => {
|
|
49
49
|
app.command("start").auth().option("--db-sync").option("--quickstart").action(async (...cliArgs) => {
|
|
50
50
|
const [options] = cliArgs;
|
|
51
|
-
const file = (0,
|
|
51
|
+
const file = (0, import_utils.storagePathJoin)(".upgrading");
|
|
52
52
|
const upgrading = await import_fs_extra.default.exists(file);
|
|
53
53
|
if (upgrading) {
|
|
54
54
|
if (!process.env.VITEST) {
|
package/lib/event-queue.js
CHANGED
|
@@ -71,7 +71,7 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
|
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
73
|
get storagePath() {
|
|
74
|
-
return
|
|
74
|
+
return (0, import_utils.storagePathJoin)("apps", this.options.appName, "event-queue.json");
|
|
75
75
|
}
|
|
76
76
|
listen = /* @__PURE__ */ __name((channel) => {
|
|
77
77
|
if (!this.connected) {
|
package/lib/gateway/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { IPCSocketClient } from './ipc-socket-client';
|
|
|
19
19
|
import { IPCSocketServer } from './ipc-socket-server';
|
|
20
20
|
import { WSServer } from './ws-server';
|
|
21
21
|
import { Duplex } from 'node:stream';
|
|
22
|
+
export { getHost, getHostname } from './utils';
|
|
22
23
|
export interface IncomingRequest {
|
|
23
24
|
url: string;
|
|
24
25
|
headers: any;
|
|
@@ -40,7 +41,7 @@ interface RunOptions {
|
|
|
40
41
|
mainAppOptions: ApplicationOptions;
|
|
41
42
|
}
|
|
42
43
|
export interface AppSelectorMiddlewareContext {
|
|
43
|
-
req: IncomingRequest;
|
|
44
|
+
req: IncomingMessage | IncomingRequest;
|
|
44
45
|
resolvedAppName: string | null;
|
|
45
46
|
}
|
|
46
47
|
export declare class Gateway extends EventEmitter {
|
|
@@ -57,6 +58,7 @@ export declare class Gateway extends EventEmitter {
|
|
|
57
58
|
private port;
|
|
58
59
|
private host;
|
|
59
60
|
private socketPath;
|
|
61
|
+
private v2IndexTemplateCache;
|
|
60
62
|
private terminating;
|
|
61
63
|
private onTerminate;
|
|
62
64
|
private constructor();
|
|
@@ -74,9 +76,18 @@ export declare class Gateway extends EventEmitter {
|
|
|
74
76
|
code: string;
|
|
75
77
|
}): void;
|
|
76
78
|
responseErrorWithCode(code: any, res: any, options: any): void;
|
|
79
|
+
private getV2PublicPath;
|
|
80
|
+
private getAppPublicPath;
|
|
81
|
+
private isV2Request;
|
|
82
|
+
private isV2IndexRequest;
|
|
83
|
+
private getV2RuntimeConfig;
|
|
84
|
+
private getV2RuntimeConfigScript;
|
|
85
|
+
private getV2AssetPublicPath;
|
|
86
|
+
private getV2IndexTemplate;
|
|
87
|
+
private renderV2IndexHtml;
|
|
77
88
|
requestHandler(req: IncomingMessage, res: ServerResponse): Promise<void>;
|
|
78
89
|
getAppSelectorMiddlewares(): Toposort<AppSelectorMiddleware>;
|
|
79
|
-
getRequestHandleAppName(req: IncomingRequest): Promise<string>;
|
|
90
|
+
getRequestHandleAppName(req: IncomingMessage | IncomingRequest): Promise<string>;
|
|
80
91
|
getCallback(): any;
|
|
81
92
|
watch(): Promise<void>;
|
|
82
93
|
run(options: RunOptions): Promise<void>;
|
|
@@ -96,4 +107,3 @@ export declare class Gateway extends EventEmitter {
|
|
|
96
107
|
static registerWsHandler(wsServer: (req: IncomingMessage, socket: Duplex, head: Buffer, app: Application) => boolean | void): void;
|
|
97
108
|
static unregisterWsHandler(wsServer: (req: IncomingMessage, socket: Duplex, head: Buffer, app: Application) => boolean | void): void;
|
|
98
109
|
}
|
|
99
|
-
export {};
|
package/lib/gateway/index.js
CHANGED
|
@@ -39,7 +39,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
39
39
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
40
40
|
var gateway_exports = {};
|
|
41
41
|
__export(gateway_exports, {
|
|
42
|
-
Gateway: () => Gateway
|
|
42
|
+
Gateway: () => Gateway,
|
|
43
|
+
getHost: () => import_utils4.getHost,
|
|
44
|
+
getHostname: () => import_utils4.getHostname
|
|
43
45
|
});
|
|
44
46
|
module.exports = __toCommonJS(gateway_exports);
|
|
45
47
|
var import_logger = require("@nocobase/logger");
|
|
@@ -54,6 +56,7 @@ var import_fs = __toESM(require("fs"));
|
|
|
54
56
|
var import_http = __toESM(require("http"));
|
|
55
57
|
var import_koa_compose = __toESM(require("koa-compose"));
|
|
56
58
|
var import_node_util = require("node:util");
|
|
59
|
+
var import_node_os = require("node:os");
|
|
57
60
|
var import_path = require("path");
|
|
58
61
|
var import_qs = __toESM(require("qs"));
|
|
59
62
|
var import_serve_handler = __toESM(require("serve-handler"));
|
|
@@ -63,16 +66,26 @@ var import_plugin_manager = require("../plugin-manager");
|
|
|
63
66
|
var import_errors = require("./errors");
|
|
64
67
|
var import_ipc_socket_client = require("./ipc-socket-client");
|
|
65
68
|
var import_ipc_socket_server = require("./ipc-socket-server");
|
|
69
|
+
var import_utils3 = require("./utils");
|
|
66
70
|
var import_ws_server = require("./ws-server");
|
|
67
71
|
var import_node_worker_threads = require("node:worker_threads");
|
|
68
72
|
var import_node_process = __toESM(require("node:process"));
|
|
73
|
+
var import_utils4 = require("./utils");
|
|
69
74
|
const compress = (0, import_node_util.promisify)((0, import_compression.default)());
|
|
75
|
+
function normalizeBasePath(path = "") {
|
|
76
|
+
const normalized = path.replace(/\/+/g, "/").replace(/\/$/, "");
|
|
77
|
+
return normalized || "/";
|
|
78
|
+
}
|
|
79
|
+
__name(normalizeBasePath, "normalizeBasePath");
|
|
70
80
|
function getSocketPath() {
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
return
|
|
81
|
+
const socketPath = import_node_process.default.env.SOCKET_PATH;
|
|
82
|
+
if (socketPath) {
|
|
83
|
+
return (0, import_path.isAbsolute)(socketPath) ? socketPath : (0, import_path.resolve)(import_node_process.default.cwd(), socketPath);
|
|
84
|
+
}
|
|
85
|
+
if (import_node_process.default.env.NOCOBASE_RUNNING_IN_DOCKER === "true") {
|
|
86
|
+
return (0, import_path.resolve)((0, import_node_os.homedir)(), ".nocobase", "gateway.sock");
|
|
74
87
|
}
|
|
75
|
-
return (0,
|
|
88
|
+
return (0, import_utils.storagePathJoin)("gateway.sock");
|
|
76
89
|
}
|
|
77
90
|
__name(getSocketPath, "getSocketPath");
|
|
78
91
|
const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
@@ -87,7 +100,8 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
87
100
|
loggers = new import_utils.Registry();
|
|
88
101
|
port = import_node_process.default.env.APP_PORT ? parseInt(import_node_process.default.env.APP_PORT) : null;
|
|
89
102
|
host = "0.0.0.0";
|
|
90
|
-
socketPath = (
|
|
103
|
+
socketPath = getSocketPath();
|
|
104
|
+
v2IndexTemplateCache = null;
|
|
91
105
|
terminating = false;
|
|
92
106
|
onTerminate = /* @__PURE__ */ __name(async (signal) => {
|
|
93
107
|
var _a;
|
|
@@ -119,7 +133,6 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
119
133
|
constructor() {
|
|
120
134
|
super();
|
|
121
135
|
this.reset();
|
|
122
|
-
this.socketPath = getSocketPath();
|
|
123
136
|
import_node_process.default.once("SIGTERM", this.onTerminate);
|
|
124
137
|
import_node_process.default.once("SIGINT", this.onTerminate);
|
|
125
138
|
}
|
|
@@ -151,14 +164,30 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
151
164
|
this.selectorMiddlewares = new import_utils.Toposort();
|
|
152
165
|
this.addAppSelectorMiddleware(
|
|
153
166
|
async (ctx, next) => {
|
|
154
|
-
var _a;
|
|
167
|
+
var _a, _b;
|
|
155
168
|
const { req } = ctx;
|
|
156
|
-
const
|
|
169
|
+
const parsedUrl = (0, import_url.parse)(req.url);
|
|
170
|
+
const appName = (_a = import_qs.default.parse(parsedUrl.query)) == null ? void 0 : _a.__appName;
|
|
171
|
+
const apiBasePath = normalizeBasePath(import_node_process.default.env.API_BASE_PATH || "/api");
|
|
172
|
+
const appPathPrefix = `${apiBasePath}/__app/`;
|
|
173
|
+
if (req.headers["x-app"]) {
|
|
174
|
+
ctx.resolvedAppName = req.headers["x-app"];
|
|
175
|
+
}
|
|
157
176
|
if (appName) {
|
|
158
177
|
ctx.resolvedAppName = appName;
|
|
159
178
|
}
|
|
160
|
-
if (
|
|
161
|
-
|
|
179
|
+
if ((_b = parsedUrl.pathname) == null ? void 0 : _b.startsWith(appPathPrefix)) {
|
|
180
|
+
const restPath = parsedUrl.pathname.slice(appPathPrefix.length);
|
|
181
|
+
const [pathAppName, ...segments] = restPath.split("/");
|
|
182
|
+
if (pathAppName) {
|
|
183
|
+
ctx.resolvedAppName = pathAppName;
|
|
184
|
+
const rewrittenPath = `${apiBasePath}${segments.length ? `/${segments.join("/")}` : ""}`;
|
|
185
|
+
const rewrittenUrl = `${rewrittenPath}${parsedUrl.search || ""}`;
|
|
186
|
+
if (!req.originalUrl) {
|
|
187
|
+
req.originalUrl = req.url;
|
|
188
|
+
}
|
|
189
|
+
req.url = rewrittenUrl;
|
|
190
|
+
}
|
|
162
191
|
}
|
|
163
192
|
await next();
|
|
164
193
|
},
|
|
@@ -222,9 +251,79 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
222
251
|
});
|
|
223
252
|
this.responseError(res, error);
|
|
224
253
|
}
|
|
254
|
+
getV2PublicPath() {
|
|
255
|
+
return (0, import_utils3.resolveV2PublicPath)(import_node_process.default.env.APP_PUBLIC_PATH || "/");
|
|
256
|
+
}
|
|
257
|
+
getAppPublicPath() {
|
|
258
|
+
return (0, import_utils3.resolvePublicPath)(import_node_process.default.env.APP_PUBLIC_PATH || "/");
|
|
259
|
+
}
|
|
260
|
+
isV2Request(pathname) {
|
|
261
|
+
const v2PublicPath = this.getV2PublicPath();
|
|
262
|
+
return pathname === v2PublicPath.slice(0, -1) || pathname.startsWith(v2PublicPath);
|
|
263
|
+
}
|
|
264
|
+
isV2IndexRequest(pathname) {
|
|
265
|
+
if (!this.isV2Request(pathname)) {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
const v2PublicPath = this.getV2PublicPath();
|
|
269
|
+
if (pathname === v2PublicPath || pathname === v2PublicPath.slice(0, -1) || pathname === `${v2PublicPath}index.html`) {
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
return !(0, import_path.extname)(pathname);
|
|
273
|
+
}
|
|
274
|
+
getV2RuntimeConfig() {
|
|
275
|
+
return {
|
|
276
|
+
__nocobase_public_path__: this.getV2PublicPath(),
|
|
277
|
+
__nocobase_api_base_url__: import_node_process.default.env.API_BASE_URL || import_node_process.default.env.API_BASE_PATH,
|
|
278
|
+
__nocobase_api_client_storage_prefix__: import_node_process.default.env.API_CLIENT_STORAGE_PREFIX,
|
|
279
|
+
__nocobase_api_client_storage_type__: import_node_process.default.env.API_CLIENT_STORAGE_TYPE,
|
|
280
|
+
__nocobase_api_client_share_token__: import_node_process.default.env.API_CLIENT_SHARE_TOKEN === "true",
|
|
281
|
+
__nocobase_ws_url__: import_node_process.default.env.WEBSOCKET_URL || "",
|
|
282
|
+
__nocobase_ws_path__: import_node_process.default.env.WS_PATH,
|
|
283
|
+
__esm_cdn_base_url__: import_node_process.default.env.ESM_CDN_BASE_URL || "https://esm.sh",
|
|
284
|
+
__esm_cdn_suffix__: import_node_process.default.env.ESM_CDN_SUFFIX || ""
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
getV2RuntimeConfigScript() {
|
|
288
|
+
const runtimeConfig = this.getV2RuntimeConfig();
|
|
289
|
+
const scriptContent = Object.entries(runtimeConfig).map(([key, value]) => `window['${key}'] = ${JSON.stringify(value)};`).join("\n");
|
|
290
|
+
return `<script>${scriptContent}</script>`;
|
|
291
|
+
}
|
|
292
|
+
getV2AssetPublicPath() {
|
|
293
|
+
if (import_node_process.default.env.CDN_BASE_URL) {
|
|
294
|
+
return `${import_node_process.default.env.CDN_BASE_URL.replace(/\/+$/, "")}/v2/`;
|
|
295
|
+
}
|
|
296
|
+
return this.getV2PublicPath();
|
|
297
|
+
}
|
|
298
|
+
getV2IndexTemplate() {
|
|
299
|
+
const file = `${import_node_process.default.env.APP_PACKAGE_ROOT}/dist/client/v2/index.html`;
|
|
300
|
+
if (!import_fs.default.existsSync(file)) {
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
const stat = import_fs.default.statSync(file);
|
|
304
|
+
if (this.v2IndexTemplateCache && this.v2IndexTemplateCache.file === file && this.v2IndexTemplateCache.mtimeMs === stat.mtimeMs) {
|
|
305
|
+
return this.v2IndexTemplateCache.html;
|
|
306
|
+
}
|
|
307
|
+
const html = import_fs.default.readFileSync(file, "utf-8");
|
|
308
|
+
this.v2IndexTemplateCache = {
|
|
309
|
+
file,
|
|
310
|
+
mtimeMs: stat.mtimeMs,
|
|
311
|
+
html
|
|
312
|
+
};
|
|
313
|
+
return html;
|
|
314
|
+
}
|
|
315
|
+
renderV2IndexHtml() {
|
|
316
|
+
const template = this.getV2IndexTemplate();
|
|
317
|
+
if (!template) {
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
const html = (0, import_utils3.rewriteV2AssetPublicPath)(template, this.getV2AssetPublicPath());
|
|
321
|
+
return (0, import_utils3.injectRuntimeScript)(html, this.getV2RuntimeConfigScript());
|
|
322
|
+
}
|
|
225
323
|
async requestHandler(req, res) {
|
|
226
324
|
const { pathname } = (0, import_url.parse)(req.url);
|
|
227
|
-
const { PLUGIN_STATICS_PATH
|
|
325
|
+
const { PLUGIN_STATICS_PATH } = import_node_process.default.env;
|
|
326
|
+
const APP_PUBLIC_PATH = this.getAppPublicPath();
|
|
228
327
|
if (pathname.endsWith("/__umi/api/bundle-status")) {
|
|
229
328
|
res.statusCode = 200;
|
|
230
329
|
res.end("ok");
|
|
@@ -246,10 +345,10 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
246
345
|
return;
|
|
247
346
|
}
|
|
248
347
|
}
|
|
249
|
-
req.url = req.url.substring(APP_PUBLIC_PATH.length
|
|
348
|
+
req.url = req.url.substring(APP_PUBLIC_PATH.length + "storage".length);
|
|
250
349
|
await compress(req, res);
|
|
251
350
|
return (0, import_serve_handler.default)(req, res, {
|
|
252
|
-
public: (0,
|
|
351
|
+
public: (0, import_utils.resolveStorageRoot)(),
|
|
253
352
|
directoryListing: false
|
|
254
353
|
});
|
|
255
354
|
}
|
|
@@ -275,6 +374,27 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
275
374
|
});
|
|
276
375
|
}
|
|
277
376
|
if (!pathname.startsWith(import_node_process.default.env.API_BASE_PATH)) {
|
|
377
|
+
if (this.isV2Request(pathname)) {
|
|
378
|
+
if (handleApp !== "main") {
|
|
379
|
+
const isProxy = await supervisor.proxyWeb(handleApp, req, res);
|
|
380
|
+
if (isProxy) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (this.isV2IndexRequest(pathname)) {
|
|
385
|
+
const v2Html = this.renderV2IndexHtml();
|
|
386
|
+
if (v2Html) {
|
|
387
|
+
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
388
|
+
res.end(v2Html);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
req.url = req.url.substring(APP_PUBLIC_PATH.length - 1);
|
|
393
|
+
await compress(req, res);
|
|
394
|
+
return (0, import_serve_handler.default)(req, res, {
|
|
395
|
+
public: `${import_node_process.default.env.APP_PACKAGE_ROOT}/dist/client`
|
|
396
|
+
});
|
|
397
|
+
}
|
|
278
398
|
if (handleApp !== "main") {
|
|
279
399
|
const isProxy = await supervisor.proxyWeb(handleApp, req, res);
|
|
280
400
|
if (isProxy) {
|
|
@@ -541,5 +661,7 @@ __publicField(_Gateway, "wsServers", []);
|
|
|
541
661
|
let Gateway = _Gateway;
|
|
542
662
|
// Annotate the CommonJS export names for ESM import in node:
|
|
543
663
|
0 && (module.exports = {
|
|
544
|
-
Gateway
|
|
664
|
+
Gateway,
|
|
665
|
+
getHost,
|
|
666
|
+
getHostname
|
|
545
667
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
/// <reference types="node" />
|
|
10
|
+
import { IncomingMessage } from 'http';
|
|
11
|
+
import { IncomingRequest } from '.';
|
|
12
|
+
export declare function resolvePublicPath(appPublicPath?: string): string;
|
|
13
|
+
export declare function resolveV2PublicPath(appPublicPath?: string): string;
|
|
14
|
+
export declare function rewriteV2AssetPublicPath(html: string, assetPublicPath: string): string;
|
|
15
|
+
export declare function injectRuntimeScript(html: string, runtimeScript: string): string;
|
|
16
|
+
export declare function getHost(req: IncomingMessage | IncomingRequest): any;
|
|
17
|
+
export declare function getHostname(req: IncomingMessage | IncomingRequest): any;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var utils_exports = {};
|
|
29
|
+
__export(utils_exports, {
|
|
30
|
+
getHost: () => getHost,
|
|
31
|
+
getHostname: () => getHostname,
|
|
32
|
+
injectRuntimeScript: () => injectRuntimeScript,
|
|
33
|
+
resolvePublicPath: () => resolvePublicPath,
|
|
34
|
+
resolveV2PublicPath: () => resolveV2PublicPath,
|
|
35
|
+
rewriteV2AssetPublicPath: () => rewriteV2AssetPublicPath
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(utils_exports);
|
|
38
|
+
function resolvePublicPath(appPublicPath = "/") {
|
|
39
|
+
const normalized = String(appPublicPath || "/").trim() || "/";
|
|
40
|
+
const withLeadingSlash = normalized.startsWith("/") ? normalized : `/${normalized}`;
|
|
41
|
+
return withLeadingSlash.endsWith("/") ? withLeadingSlash : `${withLeadingSlash}/`;
|
|
42
|
+
}
|
|
43
|
+
__name(resolvePublicPath, "resolvePublicPath");
|
|
44
|
+
function resolveV2PublicPath(appPublicPath = "/") {
|
|
45
|
+
const publicPath = resolvePublicPath(appPublicPath);
|
|
46
|
+
return `${publicPath.replace(/\/$/, "")}/v2/`;
|
|
47
|
+
}
|
|
48
|
+
__name(resolveV2PublicPath, "resolveV2PublicPath");
|
|
49
|
+
function ensureTrailingSlash(value) {
|
|
50
|
+
return value.endsWith("/") ? value : `${value}/`;
|
|
51
|
+
}
|
|
52
|
+
__name(ensureTrailingSlash, "ensureTrailingSlash");
|
|
53
|
+
function rewriteV2AssetPublicPath(html, assetPublicPath) {
|
|
54
|
+
const normalizedAssetPublicPath = ensureTrailingSlash(assetPublicPath);
|
|
55
|
+
if (normalizedAssetPublicPath === "/v2/") {
|
|
56
|
+
return html;
|
|
57
|
+
}
|
|
58
|
+
return html.replace(/((?:src|href)=["'])\/v2\//g, `$1${normalizedAssetPublicPath}`);
|
|
59
|
+
}
|
|
60
|
+
__name(rewriteV2AssetPublicPath, "rewriteV2AssetPublicPath");
|
|
61
|
+
function injectRuntimeScript(html, runtimeScript) {
|
|
62
|
+
const browserCheckerScriptMatch = html.match(/<script\b[^>]*browser-checker\.js[^>]*><\/script>/i);
|
|
63
|
+
if (browserCheckerScriptMatch == null ? void 0 : browserCheckerScriptMatch[0]) {
|
|
64
|
+
return html.replace(browserCheckerScriptMatch[0], `${runtimeScript}
|
|
65
|
+
${browserCheckerScriptMatch[0]}`);
|
|
66
|
+
}
|
|
67
|
+
const moduleScriptMatch = html.match(/<script\b[^>]*type=["']module["'][^>]*>/i);
|
|
68
|
+
if (moduleScriptMatch == null ? void 0 : moduleScriptMatch[0]) {
|
|
69
|
+
return html.replace(moduleScriptMatch[0], `${runtimeScript}
|
|
70
|
+
${moduleScriptMatch[0]}`);
|
|
71
|
+
}
|
|
72
|
+
if (html.includes("</head>")) {
|
|
73
|
+
return html.replace("</head>", `${runtimeScript}
|
|
74
|
+
</head>`);
|
|
75
|
+
}
|
|
76
|
+
return `${runtimeScript}
|
|
77
|
+
${html}`;
|
|
78
|
+
}
|
|
79
|
+
__name(injectRuntimeScript, "injectRuntimeScript");
|
|
80
|
+
function splitCommaSeparatedValues(value, limit) {
|
|
81
|
+
return value.split(",", limit).map((v) => v.trim());
|
|
82
|
+
}
|
|
83
|
+
__name(splitCommaSeparatedValues, "splitCommaSeparatedValues");
|
|
84
|
+
function getHost(req) {
|
|
85
|
+
let host = req.headers["x-forwarded-host"];
|
|
86
|
+
if (!host) {
|
|
87
|
+
host = req.headers[":authority"] || req.headers["host"];
|
|
88
|
+
}
|
|
89
|
+
if (!host) return "";
|
|
90
|
+
host = splitCommaSeparatedValues(host, 1)[0];
|
|
91
|
+
if (host.includes("@")) {
|
|
92
|
+
try {
|
|
93
|
+
host = new URL(`http://${host}`).host;
|
|
94
|
+
} catch (e) {
|
|
95
|
+
return "";
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return host;
|
|
99
|
+
}
|
|
100
|
+
__name(getHost, "getHost");
|
|
101
|
+
function getHostname(req) {
|
|
102
|
+
const host = getHost(req);
|
|
103
|
+
if (!host) return "";
|
|
104
|
+
return host.split(":", 1)[0];
|
|
105
|
+
}
|
|
106
|
+
__name(getHostname, "getHostname");
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
getHost,
|
|
110
|
+
getHostname,
|
|
111
|
+
injectRuntimeScript,
|
|
112
|
+
resolvePublicPath,
|
|
113
|
+
resolveV2PublicPath,
|
|
114
|
+
rewriteV2AssetPublicPath
|
|
115
|
+
});
|
|
@@ -6,6 +6,15 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
+
export type PluginClientLane = 'client' | 'client-v2';
|
|
10
|
+
export declare class PackageUrls {
|
|
11
|
+
static items: Record<string, string | undefined>;
|
|
12
|
+
static clear(): void;
|
|
13
|
+
static getCacheKey(packageName: string, lane: PluginClientLane): string;
|
|
14
|
+
static get(packageName: string, lane?: PluginClientLane): Promise<string>;
|
|
15
|
+
static hasClientEntry(packageName: string, lane: PluginClientLane): Promise<boolean>;
|
|
16
|
+
static fetch(packageName: string, lane?: PluginClientLane): Promise<string>;
|
|
17
|
+
}
|
|
9
18
|
declare const _default: {
|
|
10
19
|
name: string;
|
|
11
20
|
actions: {
|
|
@@ -15,8 +24,9 @@ declare const _default: {
|
|
|
15
24
|
enable(ctx: any, next: any): Promise<void>;
|
|
16
25
|
disable(ctx: any, next: any): Promise<void>;
|
|
17
26
|
remove(ctx: any, next: any): Promise<void>;
|
|
18
|
-
list(ctx: any, next: any): Promise<
|
|
27
|
+
list(ctx: any, next: any): Promise<any>;
|
|
19
28
|
listEnabled(ctx: any, next: any): Promise<void>;
|
|
29
|
+
listEnabledV2(ctx: any, next: any): Promise<void>;
|
|
20
30
|
get(ctx: any, next: any): Promise<void>;
|
|
21
31
|
};
|
|
22
32
|
};
|