@nocobase/server 1.2.13-alpha → 1.3.0-alpha.20240710084543
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/package.json +14 -14
- package/lib/acl/available-action.d.ts +0 -13
- package/lib/acl/available-action.js +0 -71
- package/lib/acl/index.d.ts +0 -10
- package/lib/acl/index.js +0 -46
- package/lib/app-command.d.ts +0 -20
- package/lib/app-command.js +0 -82
- package/lib/app-supervisor.d.ts +0 -69
- package/lib/app-supervisor.js +0 -302
- package/lib/application.d.ts +0 -345
- package/lib/application.js +0 -876
- package/lib/cache/index.d.ts +0 -11
- package/lib/cache/index.js +0 -44
- package/lib/commands/console.d.ts +0 -11
- package/lib/commands/console.js +0 -48
- package/lib/commands/create-migration.d.ts +0 -11
- package/lib/commands/create-migration.js +0 -79
- package/lib/commands/db-auth.d.ts +0 -11
- package/lib/commands/db-auth.js +0 -38
- package/lib/commands/db-clean.d.ts +0 -11
- package/lib/commands/db-clean.js +0 -41
- package/lib/commands/db-sync.d.ts +0 -11
- package/lib/commands/db-sync.js +0 -50
- package/lib/commands/destroy.d.ts +0 -11
- package/lib/commands/destroy.js +0 -40
- package/lib/commands/index.d.ts +0 -10
- package/lib/commands/index.js +0 -82
- package/lib/commands/install.d.ts +0 -11
- package/lib/commands/install.js +0 -43
- package/lib/commands/migrator.d.ts +0 -11
- package/lib/commands/migrator.js +0 -41
- package/lib/commands/pm.d.ts +0 -11
- package/lib/commands/pm.js +0 -98
- package/lib/commands/refresh.d.ts +0 -11
- package/lib/commands/refresh.js +0 -41
- package/lib/commands/restart.d.ts +0 -11
- package/lib/commands/restart.js +0 -45
- package/lib/commands/start.d.ts +0 -11
- package/lib/commands/start.js +0 -85
- package/lib/commands/stop.d.ts +0 -11
- package/lib/commands/stop.js +0 -44
- package/lib/commands/upgrade.d.ts +0 -14
- package/lib/commands/upgrade.js +0 -39
- package/lib/cron/cron-job-manager.d.ts +0 -22
- package/lib/cron/cron-job-manager.js +0 -82
- package/lib/errors/application-not-install.d.ts +0 -12
- package/lib/errors/application-not-install.js +0 -45
- package/lib/errors/handler.d.ts +0 -11
- package/lib/errors/handler.js +0 -50
- package/lib/errors/plugin-command-error.d.ts +0 -10
- package/lib/errors/plugin-command-error.js +0 -40
- package/lib/errors/plugin-not-exist.d.ts +0 -10
- package/lib/errors/plugin-not-exist.js +0 -40
- package/lib/gateway/errors.d.ts +0 -30
- package/lib/gateway/errors.js +0 -154
- package/lib/gateway/index.d.ts +0 -79
- package/lib/gateway/index.js +0 -393
- package/lib/gateway/ipc-socket-client.d.ts +0 -27
- package/lib/gateway/ipc-socket-client.js +0 -110
- package/lib/gateway/ipc-socket-server.d.ts +0 -21
- package/lib/gateway/ipc-socket-server.js +0 -150
- package/lib/gateway/ws-server.d.ts +0 -36
- package/lib/gateway/ws-server.js +0 -196
- package/lib/helper.d.ts +0 -18
- package/lib/helper.js +0 -193
- package/lib/helpers/application-version.d.ts +0 -18
- package/lib/helpers/application-version.js +0 -88
- package/lib/index.d.ts +0 -17
- package/lib/index.js +0 -64
- package/lib/locale/index.d.ts +0 -9
- package/lib/locale/index.js +0 -30
- package/lib/locale/locale.d.ts +0 -38
- package/lib/locale/locale.js +0 -174
- package/lib/locale/resource.d.ts +0 -9
- package/lib/locale/resource.js +0 -87
- package/lib/main-data-source.d.ts +0 -12
- package/lib/main-data-source.js +0 -57
- package/lib/middlewares/data-template.d.ts +0 -10
- package/lib/middlewares/data-template.js +0 -146
- package/lib/middlewares/data-wrapping.d.ts +0 -11
- package/lib/middlewares/data-wrapping.js +0 -100
- package/lib/middlewares/i18n.d.ts +0 -9
- package/lib/middlewares/i18n.js +0 -53
- package/lib/middlewares/index.d.ts +0 -10
- package/lib/middlewares/index.js +0 -39
- package/lib/middlewares/parse-variables.d.ts +0 -9
- package/lib/middlewares/parse-variables.js +0 -95
- package/lib/middlewares/validate-filter-params.d.ts +0 -9
- package/lib/middlewares/validate-filter-params.js +0 -42
- package/lib/migration.d.ts +0 -20
- package/lib/migration.js +0 -54
- package/lib/migrations/20230912193824-package-name-unique.d.ts +0 -14
- package/lib/migrations/20230912193824-package-name-unique.js +0 -59
- package/lib/migrations/20230912294620-update-pkg.d.ts +0 -14
- package/lib/migrations/20230912294620-update-pkg.js +0 -65
- package/lib/migrations/20240106082756-update-plugins.d.ts +0 -14
- package/lib/migrations/20240106082756-update-plugins.js +0 -51
- package/lib/migrations/20240428235620-rename-plugins.d.ts +0 -14
- package/lib/migrations/20240428235620-rename-plugins.js +0 -49
- package/lib/plugin-manager/clientStaticUtils.d.ts +0 -31
- package/lib/plugin-manager/clientStaticUtils.js +0 -129
- package/lib/plugin-manager/constants.d.ts +0 -15
- package/lib/plugin-manager/constants.js +0 -135
- package/lib/plugin-manager/deps.d.ts +0 -10
- package/lib/plugin-manager/deps.js +0 -83
- package/lib/plugin-manager/index.d.ts +0 -10
- package/lib/plugin-manager/index.js +0 -32
- package/lib/plugin-manager/middleware.d.ts +0 -10
- package/lib/plugin-manager/middleware.js +0 -45
- package/lib/plugin-manager/options/collection.d.ts +0 -10
- package/lib/plugin-manager/options/collection.js +0 -47
- package/lib/plugin-manager/options/resource.d.ts +0 -23
- package/lib/plugin-manager/options/resource.js +0 -186
- package/lib/plugin-manager/plugin-manager-repository.d.ts +0 -36
- package/lib/plugin-manager/plugin-manager-repository.js +0 -158
- package/lib/plugin-manager/plugin-manager.d.ts +0 -206
- package/lib/plugin-manager/plugin-manager.js +0 -1100
- package/lib/plugin-manager/types.d.ts +0 -23
- package/lib/plugin-manager/types.js +0 -24
- package/lib/plugin-manager/utils.d.ts +0 -115
- package/lib/plugin-manager/utils.js +0 -568
- package/lib/plugin.d.ts +0 -99
- package/lib/plugin.js +0 -228
- package/lib/swagger/index.json +0 -1569
package/lib/gateway/index.js
DELETED
|
@@ -1,393 +0,0 @@
|
|
|
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 __create = Object.create;
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
17
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
18
|
-
var __export = (target, all) => {
|
|
19
|
-
for (var name in all)
|
|
20
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
21
|
-
};
|
|
22
|
-
var __copyProps = (to, from, except, desc) => {
|
|
23
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
24
|
-
for (let key of __getOwnPropNames(from))
|
|
25
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
26
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
27
|
-
}
|
|
28
|
-
return to;
|
|
29
|
-
};
|
|
30
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
31
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
32
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
33
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
34
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
35
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
36
|
-
mod
|
|
37
|
-
));
|
|
38
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
39
|
-
var __publicField = (obj, key, value) => {
|
|
40
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
41
|
-
return value;
|
|
42
|
-
};
|
|
43
|
-
var gateway_exports = {};
|
|
44
|
-
__export(gateway_exports, {
|
|
45
|
-
Gateway: () => Gateway
|
|
46
|
-
});
|
|
47
|
-
module.exports = __toCommonJS(gateway_exports);
|
|
48
|
-
var import_logger = require("@nocobase/logger");
|
|
49
|
-
var import_utils = require("@nocobase/utils");
|
|
50
|
-
var import_plugin_symlink = require("@nocobase/utils/plugin-symlink");
|
|
51
|
-
var import_commander = require("commander");
|
|
52
|
-
var import_compression = __toESM(require("compression"));
|
|
53
|
-
var import_crypto = require("crypto");
|
|
54
|
-
var import_events = require("events");
|
|
55
|
-
var import_fs = __toESM(require("fs"));
|
|
56
|
-
var import_http = __toESM(require("http"));
|
|
57
|
-
var import_koa_compose = __toESM(require("koa-compose"));
|
|
58
|
-
var import_node_util = require("node:util");
|
|
59
|
-
var import_path = require("path");
|
|
60
|
-
var import_qs = __toESM(require("qs"));
|
|
61
|
-
var import_serve_handler = __toESM(require("serve-handler"));
|
|
62
|
-
var import_url = require("url");
|
|
63
|
-
var import_app_supervisor = require("../app-supervisor");
|
|
64
|
-
var import_plugin_manager = require("../plugin-manager");
|
|
65
|
-
var import_errors = require("./errors");
|
|
66
|
-
var import_ipc_socket_client = require("./ipc-socket-client");
|
|
67
|
-
var import_ipc_socket_server = require("./ipc-socket-server");
|
|
68
|
-
var import_ws_server = require("./ws-server");
|
|
69
|
-
const compress = (0, import_node_util.promisify)((0, import_compression.default)());
|
|
70
|
-
const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
71
|
-
/**
|
|
72
|
-
* use main app as default app to handle request
|
|
73
|
-
*/
|
|
74
|
-
selectorMiddlewares = new import_utils.Toposort();
|
|
75
|
-
server = null;
|
|
76
|
-
ipcSocketServer = null;
|
|
77
|
-
loggers = new import_utils.Registry();
|
|
78
|
-
port = process.env.APP_PORT ? parseInt(process.env.APP_PORT) : null;
|
|
79
|
-
host = "0.0.0.0";
|
|
80
|
-
wsServer;
|
|
81
|
-
socketPath = (0, import_path.resolve)(process.cwd(), "storage", "gateway.sock");
|
|
82
|
-
constructor() {
|
|
83
|
-
super();
|
|
84
|
-
this.reset();
|
|
85
|
-
if (process.env.SOCKET_PATH) {
|
|
86
|
-
this.socketPath = (0, import_path.resolve)(process.cwd(), process.env.SOCKET_PATH);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
static getInstance(options = {}) {
|
|
90
|
-
if (!_Gateway.instance) {
|
|
91
|
-
_Gateway.instance = new _Gateway();
|
|
92
|
-
}
|
|
93
|
-
return _Gateway.instance;
|
|
94
|
-
}
|
|
95
|
-
static async getIPCSocketClient() {
|
|
96
|
-
const socketPath = (0, import_path.resolve)(process.cwd(), process.env.SOCKET_PATH || "storage/gateway.sock");
|
|
97
|
-
try {
|
|
98
|
-
return await import_ipc_socket_client.IPCSocketClient.getConnection(socketPath);
|
|
99
|
-
} catch (error) {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
destroy() {
|
|
104
|
-
this.reset();
|
|
105
|
-
_Gateway.instance = null;
|
|
106
|
-
}
|
|
107
|
-
reset() {
|
|
108
|
-
this.selectorMiddlewares = new import_utils.Toposort();
|
|
109
|
-
this.addAppSelectorMiddleware(
|
|
110
|
-
async (ctx, next) => {
|
|
111
|
-
var _a;
|
|
112
|
-
const { req } = ctx;
|
|
113
|
-
const appName = (_a = import_qs.default.parse((0, import_url.parse)(req.url).query)) == null ? void 0 : _a.__appName;
|
|
114
|
-
if (appName) {
|
|
115
|
-
ctx.resolvedAppName = appName;
|
|
116
|
-
}
|
|
117
|
-
if (req.headers["x-app"]) {
|
|
118
|
-
ctx.resolvedAppName = req.headers["x-app"];
|
|
119
|
-
}
|
|
120
|
-
await next();
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
tag: "core",
|
|
124
|
-
group: "core"
|
|
125
|
-
}
|
|
126
|
-
);
|
|
127
|
-
if (this.server) {
|
|
128
|
-
this.server.close();
|
|
129
|
-
this.server = null;
|
|
130
|
-
}
|
|
131
|
-
if (this.ipcSocketServer) {
|
|
132
|
-
this.ipcSocketServer.close();
|
|
133
|
-
this.ipcSocketServer = null;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
addAppSelectorMiddleware(middleware, options) {
|
|
137
|
-
if (this.selectorMiddlewares.nodes.some((existingFunc) => existingFunc.toString() === middleware.toString())) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
this.selectorMiddlewares.add(middleware, options);
|
|
141
|
-
this.emit("appSelectorChanged");
|
|
142
|
-
}
|
|
143
|
-
getLogger(appName, res) {
|
|
144
|
-
const reqId = (0, import_crypto.randomUUID)();
|
|
145
|
-
res.setHeader("X-Request-Id", reqId);
|
|
146
|
-
let logger = this.loggers.get(appName);
|
|
147
|
-
if (logger) {
|
|
148
|
-
return logger.child({ reqId });
|
|
149
|
-
}
|
|
150
|
-
logger = (0, import_logger.createSystemLogger)({
|
|
151
|
-
dirname: (0, import_logger.getLoggerFilePath)(appName),
|
|
152
|
-
filename: "system",
|
|
153
|
-
defaultMeta: {
|
|
154
|
-
app: appName,
|
|
155
|
-
module: "gateway"
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
this.loggers.register(appName, logger);
|
|
159
|
-
return logger.child({ reqId });
|
|
160
|
-
}
|
|
161
|
-
responseError(res, error) {
|
|
162
|
-
res.setHeader("Content-Type", "application/json");
|
|
163
|
-
res.statusCode = error.status;
|
|
164
|
-
res.end(JSON.stringify({ error }));
|
|
165
|
-
}
|
|
166
|
-
responseErrorWithCode(code, res, options) {
|
|
167
|
-
const log = this.getLogger(options.appName, res);
|
|
168
|
-
const error = (0, import_errors.applyErrorWithArgs)((0, import_errors.getErrorWithCode)(code), options);
|
|
169
|
-
log.error(error.message, { method: "responseErrorWithCode", error });
|
|
170
|
-
this.responseError(res, error);
|
|
171
|
-
}
|
|
172
|
-
async requestHandler(req, res) {
|
|
173
|
-
const { pathname } = (0, import_url.parse)(req.url);
|
|
174
|
-
const { PLUGIN_STATICS_PATH, APP_PUBLIC_PATH } = process.env;
|
|
175
|
-
if (pathname.endsWith("/__umi/api/bundle-status")) {
|
|
176
|
-
res.statusCode = 200;
|
|
177
|
-
res.end("ok");
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
if (pathname.startsWith(APP_PUBLIC_PATH + "storage/uploads/")) {
|
|
181
|
-
req.url = req.url.substring(APP_PUBLIC_PATH.length - 1);
|
|
182
|
-
await compress(req, res);
|
|
183
|
-
return (0, import_serve_handler.default)(req, res, {
|
|
184
|
-
public: (0, import_path.resolve)(process.cwd()),
|
|
185
|
-
directoryListing: false
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
if (pathname.startsWith(PLUGIN_STATICS_PATH) && !pathname.includes("/server/")) {
|
|
189
|
-
await compress(req, res);
|
|
190
|
-
const packageName = (0, import_plugin_manager.getPackageNameByExposeUrl)(pathname);
|
|
191
|
-
const publicDir = (0, import_plugin_manager.getPackageDirByExposeUrl)(pathname);
|
|
192
|
-
const destination = pathname.replace(PLUGIN_STATICS_PATH, "").replace(packageName, "");
|
|
193
|
-
return (0, import_serve_handler.default)(req, res, {
|
|
194
|
-
public: publicDir,
|
|
195
|
-
rewrites: [
|
|
196
|
-
{
|
|
197
|
-
source: pathname,
|
|
198
|
-
destination
|
|
199
|
-
}
|
|
200
|
-
]
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
if (!pathname.startsWith(process.env.API_BASE_PATH)) {
|
|
204
|
-
req.url = req.url.substring(APP_PUBLIC_PATH.length - 1);
|
|
205
|
-
await compress(req, res);
|
|
206
|
-
return (0, import_serve_handler.default)(req, res, {
|
|
207
|
-
public: `${process.env.APP_PACKAGE_ROOT}/dist/client`,
|
|
208
|
-
rewrites: [{ source: "/**", destination: "/index.html" }]
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
const handleApp = await this.getRequestHandleAppName(req);
|
|
212
|
-
const log = this.getLogger(handleApp, res);
|
|
213
|
-
const hasApp = import_app_supervisor.AppSupervisor.getInstance().hasApp(handleApp);
|
|
214
|
-
if (!hasApp) {
|
|
215
|
-
void import_app_supervisor.AppSupervisor.getInstance().bootStrapApp(handleApp);
|
|
216
|
-
}
|
|
217
|
-
let appStatus = import_app_supervisor.AppSupervisor.getInstance().getAppStatus(handleApp, "initializing");
|
|
218
|
-
if (appStatus === "not_found") {
|
|
219
|
-
log.warn(`app not found`, { method: "requestHandler" });
|
|
220
|
-
this.responseErrorWithCode("APP_NOT_FOUND", res, { appName: handleApp });
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
if (appStatus === "initializing") {
|
|
224
|
-
this.responseErrorWithCode("APP_INITIALIZING", res, { appName: handleApp });
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
if (appStatus === "initialized") {
|
|
228
|
-
const appInstance = await import_app_supervisor.AppSupervisor.getInstance().getApp(handleApp);
|
|
229
|
-
appInstance.runCommand("start", "--quickstart");
|
|
230
|
-
appStatus = import_app_supervisor.AppSupervisor.getInstance().getAppStatus(handleApp);
|
|
231
|
-
}
|
|
232
|
-
const app = await import_app_supervisor.AppSupervisor.getInstance().getApp(handleApp);
|
|
233
|
-
if (appStatus !== "running") {
|
|
234
|
-
log.warn(`app is not running`, { method: "requestHandler", status: appStatus });
|
|
235
|
-
this.responseErrorWithCode(`${appStatus}`, res, { app, appName: handleApp });
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
if (req.url.endsWith("/__health_check")) {
|
|
239
|
-
res.statusCode = 200;
|
|
240
|
-
res.end("ok");
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
if (handleApp !== "main") {
|
|
244
|
-
import_app_supervisor.AppSupervisor.getInstance().touchApp(handleApp);
|
|
245
|
-
}
|
|
246
|
-
app.callback()(req, res);
|
|
247
|
-
}
|
|
248
|
-
getAppSelectorMiddlewares() {
|
|
249
|
-
return this.selectorMiddlewares;
|
|
250
|
-
}
|
|
251
|
-
async getRequestHandleAppName(req) {
|
|
252
|
-
const appSelectorMiddlewares = this.selectorMiddlewares.sort();
|
|
253
|
-
const ctx = {
|
|
254
|
-
req,
|
|
255
|
-
resolvedAppName: null
|
|
256
|
-
};
|
|
257
|
-
await (0, import_koa_compose.default)(appSelectorMiddlewares)(ctx);
|
|
258
|
-
if (!ctx.resolvedAppName) {
|
|
259
|
-
ctx.resolvedAppName = "main";
|
|
260
|
-
}
|
|
261
|
-
return ctx.resolvedAppName;
|
|
262
|
-
}
|
|
263
|
-
getCallback() {
|
|
264
|
-
return this.requestHandler.bind(this);
|
|
265
|
-
}
|
|
266
|
-
/* istanbul ignore next -- @preserve */
|
|
267
|
-
async watch() {
|
|
268
|
-
if (!process.env.IS_DEV_CMD) {
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
const file = (0, import_path.resolve)(process.cwd(), "storage/app.watch.ts");
|
|
272
|
-
if (!import_fs.default.existsSync(file)) {
|
|
273
|
-
await import_fs.default.promises.writeFile(file, `export const watchId = '${(0, import_utils.uid)()}';`, "utf-8");
|
|
274
|
-
}
|
|
275
|
-
require(file);
|
|
276
|
-
}
|
|
277
|
-
/* istanbul ignore next -- @preserve */
|
|
278
|
-
async run(options) {
|
|
279
|
-
const isStart = this.isStart();
|
|
280
|
-
let ipcClient;
|
|
281
|
-
if (isStart) {
|
|
282
|
-
await this.watch();
|
|
283
|
-
const startOptions = this.getStartOptions();
|
|
284
|
-
const port = startOptions.port || process.env.APP_PORT || 13e3;
|
|
285
|
-
const host = startOptions.host || process.env.APP_HOST || "0.0.0.0";
|
|
286
|
-
this.start({
|
|
287
|
-
port,
|
|
288
|
-
host
|
|
289
|
-
});
|
|
290
|
-
} else if (!this.isHelp()) {
|
|
291
|
-
ipcClient = await this.tryConnectToIPCServer();
|
|
292
|
-
if (ipcClient) {
|
|
293
|
-
const response = await ipcClient.write({ type: "passCliArgv", payload: { argv: process.argv } });
|
|
294
|
-
ipcClient.close();
|
|
295
|
-
if (!["error", "not_found"].includes(response.type)) {
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
if (isStart || !ipcClient) {
|
|
301
|
-
await (0, import_plugin_symlink.createStoragePluginsSymlink)();
|
|
302
|
-
}
|
|
303
|
-
const mainApp = import_app_supervisor.AppSupervisor.getInstance().bootMainApp(options.mainAppOptions);
|
|
304
|
-
mainApp.runAsCLI(process.argv, {
|
|
305
|
-
throwError: true,
|
|
306
|
-
from: "node"
|
|
307
|
-
}).then(async () => {
|
|
308
|
-
if (!isStart && !await mainApp.isStarted()) {
|
|
309
|
-
await mainApp.stop({ logging: false });
|
|
310
|
-
}
|
|
311
|
-
}).catch(async (e) => {
|
|
312
|
-
if (e.code !== "commander.helpDisplayed") {
|
|
313
|
-
mainApp.log.error(e);
|
|
314
|
-
}
|
|
315
|
-
if (!isStart && !await mainApp.isStarted()) {
|
|
316
|
-
await mainApp.stop({ logging: false });
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
isStart() {
|
|
321
|
-
const argv = process.argv;
|
|
322
|
-
return argv[2] === "start";
|
|
323
|
-
}
|
|
324
|
-
isHelp() {
|
|
325
|
-
const argv = process.argv;
|
|
326
|
-
return argv[2] === "help";
|
|
327
|
-
}
|
|
328
|
-
getStartOptions() {
|
|
329
|
-
const program = new import_commander.Command();
|
|
330
|
-
program.allowUnknownOption().option("-s, --silent").option("-p, --port [post]").option("-h, --host [host]").option("--db-sync").parse(process.argv);
|
|
331
|
-
return program.opts();
|
|
332
|
-
}
|
|
333
|
-
start(options) {
|
|
334
|
-
this.startHttpServer(options);
|
|
335
|
-
this.startIPCSocketServer();
|
|
336
|
-
}
|
|
337
|
-
startIPCSocketServer() {
|
|
338
|
-
this.ipcSocketServer = import_ipc_socket_server.IPCSocketServer.buildServer(this.socketPath);
|
|
339
|
-
}
|
|
340
|
-
startHttpServer(options) {
|
|
341
|
-
if ((options == null ? void 0 : options.port) !== null) {
|
|
342
|
-
this.port = options.port;
|
|
343
|
-
}
|
|
344
|
-
if (options == null ? void 0 : options.host) {
|
|
345
|
-
this.host = options.host;
|
|
346
|
-
}
|
|
347
|
-
if (this.port === null) {
|
|
348
|
-
console.log("gateway port is not set, http server will not start");
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
this.server = import_http.default.createServer(this.getCallback());
|
|
352
|
-
this.wsServer = new import_ws_server.WSServer();
|
|
353
|
-
this.server.on("upgrade", (request, socket, head) => {
|
|
354
|
-
const { pathname } = (0, import_url.parse)(request.url);
|
|
355
|
-
if (pathname === process.env.WS_PATH) {
|
|
356
|
-
this.wsServer.wss.handleUpgrade(request, socket, head, (ws) => {
|
|
357
|
-
this.wsServer.wss.emit("connection", ws, request);
|
|
358
|
-
});
|
|
359
|
-
} else {
|
|
360
|
-
socket.destroy();
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
this.server.listen(this.port, this.host, () => {
|
|
364
|
-
console.log(`Gateway HTTP Server running at http://${this.host}:${this.port}/`);
|
|
365
|
-
if (options == null ? void 0 : options.callback) {
|
|
366
|
-
options.callback(this.server);
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
async tryConnectToIPCServer() {
|
|
371
|
-
try {
|
|
372
|
-
const ipcClient = await this.getIPCSocketClient();
|
|
373
|
-
return ipcClient;
|
|
374
|
-
} catch (e) {
|
|
375
|
-
return false;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
async getIPCSocketClient() {
|
|
379
|
-
return await import_ipc_socket_client.IPCSocketClient.getConnection(this.socketPath);
|
|
380
|
-
}
|
|
381
|
-
close() {
|
|
382
|
-
var _a, _b;
|
|
383
|
-
(_a = this.server) == null ? void 0 : _a.close();
|
|
384
|
-
(_b = this.wsServer) == null ? void 0 : _b.close();
|
|
385
|
-
}
|
|
386
|
-
};
|
|
387
|
-
__name(_Gateway, "Gateway");
|
|
388
|
-
__publicField(_Gateway, "instance");
|
|
389
|
-
let Gateway = _Gateway;
|
|
390
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
391
|
-
0 && (module.exports = {
|
|
392
|
-
Gateway
|
|
393
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
/// <reference types="node" />
|
|
11
|
-
import { Logger } from '@nocobase/logger';
|
|
12
|
-
import * as events from 'events';
|
|
13
|
-
import net from 'net';
|
|
14
|
-
export declare const writeJSON: (socket: net.Socket, data: object) => void;
|
|
15
|
-
export declare class IPCSocketClient extends events.EventEmitter {
|
|
16
|
-
client: net.Socket;
|
|
17
|
-
logger: Logger;
|
|
18
|
-
constructor(client: net.Socket);
|
|
19
|
-
static getConnection(serverPath: string): Promise<IPCSocketClient>;
|
|
20
|
-
handleServerMessage({ reqId, type, payload }: {
|
|
21
|
-
reqId: any;
|
|
22
|
-
type: any;
|
|
23
|
-
payload: any;
|
|
24
|
-
}): Promise<void>;
|
|
25
|
-
close(): void;
|
|
26
|
-
write(data: any): Promise<unknown>;
|
|
27
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
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 __create = Object.create;
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
|
-
var __export = (target, all) => {
|
|
18
|
-
for (var name in all)
|
|
19
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
|
-
};
|
|
21
|
-
var __copyProps = (to, from, except, desc) => {
|
|
22
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
-
for (let key of __getOwnPropNames(from))
|
|
24
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
25
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
26
|
-
}
|
|
27
|
-
return to;
|
|
28
|
-
};
|
|
29
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
-
mod
|
|
36
|
-
));
|
|
37
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
-
var ipc_socket_client_exports = {};
|
|
39
|
-
__export(ipc_socket_client_exports, {
|
|
40
|
-
IPCSocketClient: () => IPCSocketClient,
|
|
41
|
-
writeJSON: () => writeJSON
|
|
42
|
-
});
|
|
43
|
-
module.exports = __toCommonJS(ipc_socket_client_exports);
|
|
44
|
-
var import_logger = require("@nocobase/logger");
|
|
45
|
-
var events = __toESM(require("events"));
|
|
46
|
-
var import_net = __toESM(require("net"));
|
|
47
|
-
var import_xpipe = __toESM(require("xpipe"));
|
|
48
|
-
const writeJSON = /* @__PURE__ */ __name((socket, data) => {
|
|
49
|
-
socket.write(JSON.stringify(data) + "\n", "utf8");
|
|
50
|
-
}, "writeJSON");
|
|
51
|
-
const _IPCSocketClient = class _IPCSocketClient extends events.EventEmitter {
|
|
52
|
-
client;
|
|
53
|
-
logger;
|
|
54
|
-
constructor(client) {
|
|
55
|
-
super();
|
|
56
|
-
this.logger = (0, import_logger.createConsoleLogger)();
|
|
57
|
-
this.client = client;
|
|
58
|
-
this.client.on("data", (data) => {
|
|
59
|
-
const dataAsString = data.toString();
|
|
60
|
-
const messages = dataAsString.split("\n");
|
|
61
|
-
for (const message of messages) {
|
|
62
|
-
if (message.length === 0) {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
const dataObj = JSON.parse(message);
|
|
66
|
-
this.handleServerMessage(dataObj);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
static async getConnection(serverPath) {
|
|
71
|
-
return new Promise((resolve, reject) => {
|
|
72
|
-
const client = import_net.default.createConnection({ path: import_xpipe.default.eq(serverPath) }, () => {
|
|
73
|
-
resolve(new _IPCSocketClient(client));
|
|
74
|
-
});
|
|
75
|
-
client.on("error", (err) => {
|
|
76
|
-
reject(err);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
async handleServerMessage({ reqId, type, payload }) {
|
|
81
|
-
switch (type) {
|
|
82
|
-
case "not_found":
|
|
83
|
-
break;
|
|
84
|
-
case "error":
|
|
85
|
-
this.logger.error({ reqId, message: `${payload.message}|${payload.stack}` });
|
|
86
|
-
break;
|
|
87
|
-
case "success":
|
|
88
|
-
this.logger.info({ reqId, message: "success" });
|
|
89
|
-
break;
|
|
90
|
-
default:
|
|
91
|
-
this.logger.info({ reqId, message: JSON.stringify({ type, payload }) });
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
this.emit("response", { reqId, type, payload });
|
|
95
|
-
}
|
|
96
|
-
close() {
|
|
97
|
-
this.client.end();
|
|
98
|
-
}
|
|
99
|
-
write(data) {
|
|
100
|
-
writeJSON(this.client, data);
|
|
101
|
-
return new Promise((resolve) => this.once("response", resolve));
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
__name(_IPCSocketClient, "IPCSocketClient");
|
|
105
|
-
let IPCSocketClient = _IPCSocketClient;
|
|
106
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
-
0 && (module.exports = {
|
|
108
|
-
IPCSocketClient,
|
|
109
|
-
writeJSON
|
|
110
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
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 net from 'net';
|
|
11
|
-
export declare class IPCSocketServer {
|
|
12
|
-
socketServer: net.Server;
|
|
13
|
-
constructor(server: net.Server);
|
|
14
|
-
static buildServer(socketPath: string): IPCSocketServer;
|
|
15
|
-
static handleClientMessage({ reqId, type, payload }: {
|
|
16
|
-
reqId: any;
|
|
17
|
-
type: any;
|
|
18
|
-
payload: any;
|
|
19
|
-
}): Promise<string | false | import("../app-command").AppCommand>;
|
|
20
|
-
close(): void;
|
|
21
|
-
}
|