@nocobase/server 2.2.0-beta.9 → 2.2.0
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/app-supervisor/index.d.ts +3 -0
- package/lib/app-supervisor/index.js +30 -12
- package/lib/app-supervisor/main-only-adapter.d.ts +0 -8
- package/lib/app-supervisor/main-only-adapter.js +0 -39
- package/lib/application.js +1 -0
- package/lib/event-queue.d.ts +3 -2
- package/lib/event-queue.js +22 -13
- package/lib/gateway/index.js +39 -7
- package/lib/gateway/static-file-security.js +23 -2
- package/lib/helper.d.ts +1 -0
- package/lib/helper.js +29 -12
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/lib/plugin-manager/findPackageNames.js +1 -0
- package/lib/swagger/app.d.ts +17 -1
- package/lib/swagger/app.js +16 -1
- package/lib/swagger/index.d.ts +17 -1
- package/package.json +17 -17
|
@@ -49,6 +49,7 @@ export declare class AppSupervisor extends EventEmitter implements AsyncEmitter
|
|
|
49
49
|
private commandAdapterName;
|
|
50
50
|
private appDbCreator;
|
|
51
51
|
private appConditions;
|
|
52
|
+
private appManifests;
|
|
52
53
|
private appSsoIssuer?;
|
|
53
54
|
appOptionsFactory: AppOptionsFactory;
|
|
54
55
|
private environmentHeartbeatInterval;
|
|
@@ -117,6 +118,8 @@ export declare class AppSupervisor extends EventEmitter implements AsyncEmitter
|
|
|
117
118
|
removeAppManifest(appName: string, namespace: string): Promise<void>;
|
|
118
119
|
getAppManifestItems<T = unknown>(appName: string, namespace: string): Promise<T[]>;
|
|
119
120
|
getAppManifests<T = unknown>(namespace: string, appNames: string[]): Promise<Record<string, T[]>>;
|
|
121
|
+
private getAppManifestKey;
|
|
122
|
+
private getOrCreateAppManifest;
|
|
120
123
|
registerAppCondition(name: string, condition: AppCondition): void;
|
|
121
124
|
unregisterAppCondition(name: string): void;
|
|
122
125
|
getAppCondition(name: string): AppCondition;
|
|
@@ -70,6 +70,7 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
70
70
|
commandAdapterName;
|
|
71
71
|
appDbCreator = new import_condition_registry.ConditionalRegistry();
|
|
72
72
|
appConditions = /* @__PURE__ */ new Map();
|
|
73
|
+
appManifests = /* @__PURE__ */ new Map();
|
|
73
74
|
appSsoIssuer;
|
|
74
75
|
appOptionsFactory = import_app_options_factory.appOptionsFactory;
|
|
75
76
|
environmentHeartbeatInterval = 2 * 60 * 1e3;
|
|
@@ -284,6 +285,7 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
284
285
|
await this.processAdapter.removeAllApps();
|
|
285
286
|
await ((_b = (_a = this.discoveryAdapter).dispose) == null ? void 0 : _b.call(_a));
|
|
286
287
|
await ((_d = (_c = this.commandAdapter) == null ? void 0 : _c.dispose) == null ? void 0 : _d.call(_c));
|
|
288
|
+
this.appManifests.clear();
|
|
287
289
|
if (this.environmentHeartbeatTimer) {
|
|
288
290
|
this.environmentHeartbeatTimer = null;
|
|
289
291
|
}
|
|
@@ -436,28 +438,31 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
436
438
|
return this.discoveryAdapter.listAppModels();
|
|
437
439
|
}
|
|
438
440
|
async setAppManifestItem(appName, namespace, itemKey, item) {
|
|
439
|
-
if (typeof this.discoveryAdapter.setAppManifestItem
|
|
440
|
-
return;
|
|
441
|
+
if (typeof this.discoveryAdapter.setAppManifestItem === "function") {
|
|
442
|
+
return this.discoveryAdapter.setAppManifestItem(appName, namespace, itemKey, item);
|
|
441
443
|
}
|
|
442
|
-
|
|
444
|
+
const manifest = this.getOrCreateAppManifest(appName, namespace);
|
|
445
|
+
manifest.set(itemKey, item);
|
|
443
446
|
}
|
|
444
447
|
async removeAppManifestItem(appName, namespace, itemKey) {
|
|
445
|
-
|
|
446
|
-
|
|
448
|
+
var _a;
|
|
449
|
+
if (typeof this.discoveryAdapter.removeAppManifestItem === "function") {
|
|
450
|
+
return this.discoveryAdapter.removeAppManifestItem(appName, namespace, itemKey);
|
|
447
451
|
}
|
|
448
|
-
|
|
452
|
+
(_a = this.appManifests.get(this.getAppManifestKey(appName, namespace))) == null ? void 0 : _a.delete(itemKey);
|
|
449
453
|
}
|
|
450
454
|
async removeAppManifest(appName, namespace) {
|
|
451
|
-
if (typeof this.discoveryAdapter.removeAppManifest
|
|
452
|
-
return;
|
|
455
|
+
if (typeof this.discoveryAdapter.removeAppManifest === "function") {
|
|
456
|
+
return this.discoveryAdapter.removeAppManifest(appName, namespace);
|
|
453
457
|
}
|
|
454
|
-
|
|
458
|
+
this.appManifests.delete(this.getAppManifestKey(appName, namespace));
|
|
455
459
|
}
|
|
456
460
|
async getAppManifestItems(appName, namespace) {
|
|
457
|
-
|
|
458
|
-
|
|
461
|
+
var _a;
|
|
462
|
+
if (typeof this.discoveryAdapter.getAppManifestItems === "function") {
|
|
463
|
+
return this.discoveryAdapter.getAppManifestItems(appName, namespace);
|
|
459
464
|
}
|
|
460
|
-
return this.
|
|
465
|
+
return Array.from(((_a = this.appManifests.get(this.getAppManifestKey(appName, namespace))) == null ? void 0 : _a.values()) || []);
|
|
461
466
|
}
|
|
462
467
|
async getAppManifests(namespace, appNames) {
|
|
463
468
|
if (typeof this.discoveryAdapter.getAppManifests === "function") {
|
|
@@ -474,6 +479,19 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
|
474
479
|
);
|
|
475
480
|
return result;
|
|
476
481
|
}
|
|
482
|
+
getAppManifestKey(appName, namespace) {
|
|
483
|
+
return `${namespace}:${appName}`;
|
|
484
|
+
}
|
|
485
|
+
getOrCreateAppManifest(appName, namespace) {
|
|
486
|
+
const key = this.getAppManifestKey(appName, namespace);
|
|
487
|
+
const manifest = this.appManifests.get(key);
|
|
488
|
+
if (manifest) {
|
|
489
|
+
return manifest;
|
|
490
|
+
}
|
|
491
|
+
const nextManifest = /* @__PURE__ */ new Map();
|
|
492
|
+
this.appManifests.set(key, nextManifest);
|
|
493
|
+
return nextManifest;
|
|
494
|
+
}
|
|
477
495
|
registerAppCondition(name, condition) {
|
|
478
496
|
this.appConditions.set(name, condition);
|
|
479
497
|
}
|
|
@@ -16,18 +16,12 @@ export declare class MainOnlyAdapter implements AppDiscoveryAdapter, AppProcessA
|
|
|
16
16
|
apps: Record<string, Application>;
|
|
17
17
|
status: AppStatus;
|
|
18
18
|
appErrors: Record<string, Error>;
|
|
19
|
-
private readonly appManifests;
|
|
20
19
|
constructor(supervisor: AppSupervisor);
|
|
21
20
|
getApp(appName: string, options?: GetAppOptions): Promise<Application<import("../application").DefaultState, import("../application").DefaultContext>>;
|
|
22
21
|
bootstrapApp(appName: string): Promise<void>;
|
|
23
22
|
addApp(app: Application): Application<import("../application").DefaultState, import("../application").DefaultContext>;
|
|
24
23
|
getApps(): Application<import("../application").DefaultState, import("../application").DefaultContext>[];
|
|
25
24
|
listAppModels(): Promise<any[]>;
|
|
26
|
-
setAppManifestItem(appName: string, namespace: string, itemKey: string, item: unknown): Promise<void>;
|
|
27
|
-
removeAppManifestItem(appName: string, namespace: string, itemKey: string): Promise<void>;
|
|
28
|
-
removeAppManifest(appName: string, namespace: string): Promise<void>;
|
|
29
|
-
getAppManifestItems<T = unknown>(appName: string, namespace: string): Promise<T[]>;
|
|
30
|
-
getAppManifests<T = unknown>(namespace: string, appNames: string[]): Promise<Record<string, T[]>>;
|
|
31
25
|
hasApp(appName: string): boolean;
|
|
32
26
|
startApp(appName: string): Promise<void>;
|
|
33
27
|
stopApp(appName: string): Promise<void>;
|
|
@@ -44,6 +38,4 @@ export declare class MainOnlyAdapter implements AppDiscoveryAdapter, AppProcessA
|
|
|
44
38
|
clearAppError(appName: string): void;
|
|
45
39
|
setAppLastSeenAt(): void;
|
|
46
40
|
getAppLastSeenAt(appName: string): any;
|
|
47
|
-
private getAppManifestKey;
|
|
48
|
-
private getOrCreateAppManifest;
|
|
49
41
|
}
|
|
@@ -39,7 +39,6 @@ const _MainOnlyAdapter = class _MainOnlyAdapter {
|
|
|
39
39
|
apps = {};
|
|
40
40
|
status;
|
|
41
41
|
appErrors = {};
|
|
42
|
-
appManifests = /* @__PURE__ */ new Map();
|
|
43
42
|
async getApp(appName, options = {}) {
|
|
44
43
|
if (appName !== "main") {
|
|
45
44
|
this.supervisor.logger.warn(`only main app is supported`, { method: "getApp", appName });
|
|
@@ -82,31 +81,6 @@ const _MainOnlyAdapter = class _MainOnlyAdapter {
|
|
|
82
81
|
async listAppModels() {
|
|
83
82
|
return [];
|
|
84
83
|
}
|
|
85
|
-
async setAppManifestItem(appName, namespace, itemKey, item) {
|
|
86
|
-
const manifest = this.getOrCreateAppManifest(appName, namespace);
|
|
87
|
-
manifest.set(itemKey, item);
|
|
88
|
-
}
|
|
89
|
-
async removeAppManifestItem(appName, namespace, itemKey) {
|
|
90
|
-
var _a;
|
|
91
|
-
(_a = this.appManifests.get(this.getAppManifestKey(appName, namespace))) == null ? void 0 : _a.delete(itemKey);
|
|
92
|
-
}
|
|
93
|
-
async removeAppManifest(appName, namespace) {
|
|
94
|
-
this.appManifests.delete(this.getAppManifestKey(appName, namespace));
|
|
95
|
-
}
|
|
96
|
-
async getAppManifestItems(appName, namespace) {
|
|
97
|
-
var _a;
|
|
98
|
-
return Array.from(((_a = this.appManifests.get(this.getAppManifestKey(appName, namespace))) == null ? void 0 : _a.values()) || []);
|
|
99
|
-
}
|
|
100
|
-
async getAppManifests(namespace, appNames) {
|
|
101
|
-
const result = {};
|
|
102
|
-
for (const appName of appNames) {
|
|
103
|
-
const data = await this.getAppManifestItems(appName, namespace);
|
|
104
|
-
if (data.length > 0) {
|
|
105
|
-
result[appName] = data;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return result;
|
|
109
|
-
}
|
|
110
84
|
hasApp(appName) {
|
|
111
85
|
if (appName !== "main") {
|
|
112
86
|
return false;
|
|
@@ -188,19 +162,6 @@ const _MainOnlyAdapter = class _MainOnlyAdapter {
|
|
|
188
162
|
getAppLastSeenAt(appName) {
|
|
189
163
|
return null;
|
|
190
164
|
}
|
|
191
|
-
getAppManifestKey(appName, namespace) {
|
|
192
|
-
return `${namespace}:${appName}`;
|
|
193
|
-
}
|
|
194
|
-
getOrCreateAppManifest(appName, namespace) {
|
|
195
|
-
const key = this.getAppManifestKey(appName, namespace);
|
|
196
|
-
const manifest = this.appManifests.get(key);
|
|
197
|
-
if (manifest) {
|
|
198
|
-
return manifest;
|
|
199
|
-
}
|
|
200
|
-
const nextManifest = /* @__PURE__ */ new Map();
|
|
201
|
-
this.appManifests.set(key, nextManifest);
|
|
202
|
-
return nextManifest;
|
|
203
|
-
}
|
|
204
165
|
};
|
|
205
166
|
__name(_MainOnlyAdapter, "MainOnlyAdapter");
|
|
206
167
|
let MainOnlyAdapter = _MainOnlyAdapter;
|
package/lib/application.js
CHANGED
|
@@ -944,6 +944,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
944
944
|
}
|
|
945
945
|
});
|
|
946
946
|
this._dataSourceManager.use(this._authManager.middleware(), { tag: "auth", before: "default" });
|
|
947
|
+
this._dataSourceManager.use(import_auth.csrfMiddleware, { tag: "csrf", after: "auth", before: "default" });
|
|
947
948
|
this._dataSourceManager.use(import_validate_filter_params.default, { tag: "validate-filter-params", before: ["auth"] });
|
|
948
949
|
this._dataSourceManager.use(import_middlewares.parseVariables, {
|
|
949
950
|
group: "parseVariables",
|
package/lib/event-queue.d.ts
CHANGED
|
@@ -53,17 +53,18 @@ export interface EventQueueOptions {
|
|
|
53
53
|
export declare class MemoryEventQueueAdapter implements IEventQueueAdapter {
|
|
54
54
|
private options;
|
|
55
55
|
private connected;
|
|
56
|
-
private emitter;
|
|
57
56
|
private reading;
|
|
57
|
+
private scheduledChannels;
|
|
58
58
|
protected events: Map<string, QueueEventOptions>;
|
|
59
59
|
protected queues: Map<string, {
|
|
60
60
|
id: string;
|
|
61
61
|
content: any;
|
|
62
62
|
options?: QueueMessageOptions;
|
|
63
63
|
}[]>;
|
|
64
|
-
get processing(): Promise<
|
|
64
|
+
get processing(): Promise<void[]>;
|
|
65
65
|
private get storagePath();
|
|
66
66
|
listen: (channel: string) => void;
|
|
67
|
+
private scheduleListen;
|
|
67
68
|
constructor(options: {
|
|
68
69
|
appName: string;
|
|
69
70
|
logger: SystemLogger;
|
package/lib/event-queue.js
CHANGED
|
@@ -46,7 +46,6 @@ __export(event_queue_exports, {
|
|
|
46
46
|
});
|
|
47
47
|
module.exports = __toCommonJS(event_queue_exports);
|
|
48
48
|
var import_crypto = require("crypto");
|
|
49
|
-
var import_events = require("events");
|
|
50
49
|
var import_path = __toESM(require("path"));
|
|
51
50
|
var import_promises = __toESM(require("fs/promises"));
|
|
52
51
|
var import_utils = require("@nocobase/utils");
|
|
@@ -56,15 +55,14 @@ const QUEUE_DEFAULT_ACK_TIMEOUT = 15e3;
|
|
|
56
55
|
const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
|
|
57
56
|
constructor(options) {
|
|
58
57
|
this.options = options;
|
|
59
|
-
this.emitter.setMaxListeners(0);
|
|
60
58
|
}
|
|
61
59
|
connected = false;
|
|
62
|
-
emitter = new import_events.EventEmitter();
|
|
63
60
|
reading = /* @__PURE__ */ new Map();
|
|
61
|
+
scheduledChannels = /* @__PURE__ */ new Set();
|
|
64
62
|
events = /* @__PURE__ */ new Map();
|
|
65
63
|
queues = /* @__PURE__ */ new Map();
|
|
66
64
|
get processing() {
|
|
67
|
-
const processing = Array.from(this.reading.values());
|
|
65
|
+
const processing = Array.from(this.reading.values()).flat();
|
|
68
66
|
if (processing.length > 0) {
|
|
69
67
|
return Promise.all(processing);
|
|
70
68
|
}
|
|
@@ -80,14 +78,15 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
|
|
|
80
78
|
const { logger } = this.options;
|
|
81
79
|
const event = this.events.get(channel);
|
|
82
80
|
if (!event) {
|
|
83
|
-
logger.warn(`memory queue (${channel}) not found, skipping...`);
|
|
84
81
|
return;
|
|
85
82
|
}
|
|
86
83
|
if (!event.idle()) {
|
|
87
84
|
return;
|
|
88
85
|
}
|
|
89
86
|
const reading = this.reading.get(channel) || [];
|
|
90
|
-
const
|
|
87
|
+
const queue = this.queues.get(channel);
|
|
88
|
+
const concurrency = event.concurrency ?? QUEUE_DEFAULT_CONCURRENCY;
|
|
89
|
+
const count = concurrency <= 0 ? (queue == null ? void 0 : queue.length) || 0 : concurrency - reading.length;
|
|
91
90
|
if (count <= 0) {
|
|
92
91
|
return;
|
|
93
92
|
}
|
|
@@ -99,10 +98,24 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
|
|
|
99
98
|
if (index > -1) {
|
|
100
99
|
reading.splice(index, 1);
|
|
101
100
|
}
|
|
101
|
+
this.scheduleListen(channel);
|
|
102
102
|
});
|
|
103
103
|
});
|
|
104
104
|
this.reading.set(channel, reading);
|
|
105
105
|
}, "listen");
|
|
106
|
+
scheduleListen(channel) {
|
|
107
|
+
if (this.scheduledChannels.has(channel)) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
this.scheduledChannels.add(channel);
|
|
111
|
+
setImmediate(() => {
|
|
112
|
+
this.scheduledChannels.delete(channel);
|
|
113
|
+
if (!this.events.has(channel)) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
this.listen(channel);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
106
119
|
isConnected() {
|
|
107
120
|
return this.connected;
|
|
108
121
|
}
|
|
@@ -181,7 +194,6 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
|
|
|
181
194
|
if (!this.queues.has(channel)) {
|
|
182
195
|
this.queues.set(channel, []);
|
|
183
196
|
}
|
|
184
|
-
this.emitter.on(channel, this.listen);
|
|
185
197
|
if (this.connected) {
|
|
186
198
|
this.consume(channel);
|
|
187
199
|
}
|
|
@@ -191,12 +203,12 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
|
|
|
191
203
|
return;
|
|
192
204
|
}
|
|
193
205
|
this.events.delete(channel);
|
|
194
|
-
this.emitter.off(channel, this.listen);
|
|
195
206
|
}
|
|
196
207
|
publish(channel, content, options = { timestamp: Date.now() }) {
|
|
208
|
+
const { logger } = this.options;
|
|
197
209
|
const event = this.events.get(channel);
|
|
198
210
|
if (!event) {
|
|
199
|
-
|
|
211
|
+
logger.debug(`memory queue (${channel}) not subscribed, skip`);
|
|
200
212
|
return;
|
|
201
213
|
}
|
|
202
214
|
if (!this.queues.get(channel)) {
|
|
@@ -205,11 +217,8 @@ const _MemoryEventQueueAdapter = class _MemoryEventQueueAdapter {
|
|
|
205
217
|
const queue = this.queues.get(channel);
|
|
206
218
|
const message = { id: (0, import_crypto.randomUUID)(), content, options };
|
|
207
219
|
queue.push(message);
|
|
208
|
-
const { logger } = this.options;
|
|
209
220
|
logger.debug(`memory queue (${channel}) published message`, content);
|
|
210
|
-
|
|
211
|
-
this.emitter.emit(channel, channel);
|
|
212
|
-
});
|
|
221
|
+
this.scheduleListen(channel);
|
|
213
222
|
}
|
|
214
223
|
async consume(channel, once = false) {
|
|
215
224
|
while (this.connected && this.events.get(channel)) {
|
package/lib/gateway/index.js
CHANGED
|
@@ -78,6 +78,17 @@ function normalizeBasePath(path = "") {
|
|
|
78
78
|
return normalized || "/";
|
|
79
79
|
}
|
|
80
80
|
__name(normalizeBasePath, "normalizeBasePath");
|
|
81
|
+
function getFilesPathPrefixes(appPublicPath = "/") {
|
|
82
|
+
const normalizedPublicPath = normalizeBasePath(appPublicPath);
|
|
83
|
+
const canonicalPrefix = `${normalizedPublicPath === "/" ? "" : normalizedPublicPath}/files/`;
|
|
84
|
+
return canonicalPrefix === "/files/" ? ["/files/"] : [canonicalPrefix, "/files/"];
|
|
85
|
+
}
|
|
86
|
+
__name(getFilesPathPrefixes, "getFilesPathPrefixes");
|
|
87
|
+
function getFileAccessRestPath(pathname, appPublicPath = "/") {
|
|
88
|
+
const prefix = getFilesPathPrefixes(appPublicPath).find((prefix2) => pathname.startsWith(prefix2));
|
|
89
|
+
return prefix ? pathname.slice(prefix.length) : null;
|
|
90
|
+
}
|
|
91
|
+
__name(getFileAccessRestPath, "getFileAccessRestPath");
|
|
81
92
|
function getSocketPath() {
|
|
82
93
|
const socketPath = import_node_process.default.env.SOCKET_PATH;
|
|
83
94
|
if (socketPath) {
|
|
@@ -202,6 +213,17 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
202
213
|
req.url = rewrittenUrl;
|
|
203
214
|
}
|
|
204
215
|
}
|
|
216
|
+
const fileAccessRestPath = parsedUrl.pathname ? getFileAccessRestPath(parsedUrl.pathname, import_node_process.default.env.APP_PUBLIC_PATH || "/") : null;
|
|
217
|
+
if (fileAccessRestPath) {
|
|
218
|
+
const restPath = fileAccessRestPath;
|
|
219
|
+
const [pathAppName] = restPath.split("/");
|
|
220
|
+
if (pathAppName) {
|
|
221
|
+
try {
|
|
222
|
+
ctx.resolvedAppName = decodeURIComponent(pathAppName);
|
|
223
|
+
} catch (error) {
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
205
227
|
await next();
|
|
206
228
|
},
|
|
207
229
|
{
|
|
@@ -337,7 +359,7 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
337
359
|
return (0, import_utils3.injectRuntimeScript)(html, this.getV2RuntimeConfigScript());
|
|
338
360
|
}
|
|
339
361
|
async requestHandler(req, res) {
|
|
340
|
-
const { pathname } = (0, import_url.parse)(req.url);
|
|
362
|
+
const { pathname, search } = (0, import_url.parse)(req.url);
|
|
341
363
|
const { PLUGIN_STATICS_PATH } = import_node_process.default.env;
|
|
342
364
|
const APP_PUBLIC_PATH = this.getAppPublicPath();
|
|
343
365
|
if (pathname.endsWith("/__umi/api/bundle-status")) {
|
|
@@ -345,6 +367,12 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
345
367
|
res.end("ok");
|
|
346
368
|
return;
|
|
347
369
|
}
|
|
370
|
+
if (APP_PUBLIC_PATH !== "/" && pathname.startsWith("/files/")) {
|
|
371
|
+
res.statusCode = 302;
|
|
372
|
+
res.setHeader("Location", `${APP_PUBLIC_PATH.replace(/\/$/, "")}${pathname}${search || ""}`);
|
|
373
|
+
res.end();
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
348
376
|
const supervisor = import_app_supervisor.AppSupervisor.getInstance();
|
|
349
377
|
let handleApp = "main";
|
|
350
378
|
try {
|
|
@@ -361,15 +389,18 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
361
389
|
return;
|
|
362
390
|
}
|
|
363
391
|
}
|
|
364
|
-
const headers = (0, import_static_file_security.getStorageUploadSecurityHeaders)(pathname);
|
|
365
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
366
|
-
res.setHeader(key, value);
|
|
367
|
-
}
|
|
392
|
+
const headers = (0, import_static_file_security.getStorageUploadSecurityHeaders)(`${pathname}${search || ""}`);
|
|
368
393
|
req.url = req.url.substring(APP_PUBLIC_PATH.length + "storage".length);
|
|
369
394
|
await compress(req, res);
|
|
370
395
|
return (0, import_serve_handler.default)(req, res, {
|
|
371
396
|
public: (0, import_utils.resolveStorageRoot)(),
|
|
372
|
-
directoryListing: false
|
|
397
|
+
directoryListing: false,
|
|
398
|
+
headers: [
|
|
399
|
+
{
|
|
400
|
+
source: "**/*",
|
|
401
|
+
headers: Object.entries(headers).map(([key, value]) => ({ key, value }))
|
|
402
|
+
}
|
|
403
|
+
]
|
|
373
404
|
});
|
|
374
405
|
}
|
|
375
406
|
if (pathname.startsWith(APP_PUBLIC_PATH + "dist/")) {
|
|
@@ -407,7 +438,8 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
|
|
|
407
438
|
]
|
|
408
439
|
});
|
|
409
440
|
}
|
|
410
|
-
|
|
441
|
+
const isFilesRequest = Boolean(getFileAccessRestPath(pathname, APP_PUBLIC_PATH));
|
|
442
|
+
if (!pathname.startsWith(import_node_process.default.env.API_BASE_PATH) && !isFilesRequest) {
|
|
411
443
|
if (this.isV2Request(pathname)) {
|
|
412
444
|
if (handleApp !== "main") {
|
|
413
445
|
const isProxy = await this.proxyRequestToSubApp(supervisor, handleApp, req, res);
|
|
@@ -42,11 +42,31 @@ __export(static_file_security_exports, {
|
|
|
42
42
|
});
|
|
43
43
|
module.exports = __toCommonJS(static_file_security_exports);
|
|
44
44
|
var import_node_path = __toESM(require("node:path"));
|
|
45
|
-
const ACTIVE_CONTENT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
45
|
+
const ACTIVE_CONTENT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
46
|
+
".htm",
|
|
47
|
+
".html",
|
|
48
|
+
".pdf",
|
|
49
|
+
".svg",
|
|
50
|
+
".svgz",
|
|
51
|
+
".xht",
|
|
52
|
+
".xhtml",
|
|
53
|
+
".xml",
|
|
54
|
+
".xsl",
|
|
55
|
+
".xslt"
|
|
56
|
+
]);
|
|
46
57
|
function stripQueryAndHash(pathname = "") {
|
|
47
58
|
return pathname.split("?")[0].split("#")[0];
|
|
48
59
|
}
|
|
49
60
|
__name(stripQueryAndHash, "stripQueryAndHash");
|
|
61
|
+
function shouldDownload(pathname = "") {
|
|
62
|
+
var _a;
|
|
63
|
+
const query = (_a = pathname.split("?")[1]) == null ? void 0 : _a.split("#")[0];
|
|
64
|
+
if (!query) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
return new URLSearchParams(query).get("download") === "1";
|
|
68
|
+
}
|
|
69
|
+
__name(shouldDownload, "shouldDownload");
|
|
50
70
|
function hasActiveContentExtension(pathname = "") {
|
|
51
71
|
const ext = import_node_path.default.extname(stripQueryAndHash(pathname)).toLowerCase();
|
|
52
72
|
return ACTIVE_CONTENT_EXTENSIONS.has(ext);
|
|
@@ -54,9 +74,10 @@ function hasActiveContentExtension(pathname = "") {
|
|
|
54
74
|
__name(hasActiveContentExtension, "hasActiveContentExtension");
|
|
55
75
|
function getStorageUploadSecurityHeaders(pathname = "") {
|
|
56
76
|
const headers = {
|
|
77
|
+
"Content-Security-Policy": "sandbox",
|
|
57
78
|
"X-Content-Type-Options": "nosniff"
|
|
58
79
|
};
|
|
59
|
-
if (hasActiveContentExtension(pathname)) {
|
|
80
|
+
if (hasActiveContentExtension(pathname) || shouldDownload(pathname)) {
|
|
60
81
|
headers["Content-Disposition"] = "attachment";
|
|
61
82
|
}
|
|
62
83
|
return headers;
|
package/lib/helper.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { Command } from 'commander';
|
|
|
11
11
|
import Application, { ApplicationOptions } from './application';
|
|
12
12
|
export declare function createI18n(options: ApplicationOptions): import("i18next").i18n;
|
|
13
13
|
export declare function createResourcer(options: ApplicationOptions): Resourcer;
|
|
14
|
+
export declare function resolveCorsOrigin(ctx: any): any;
|
|
14
15
|
export declare function registerMiddlewares(app: Application, options: ApplicationOptions): void;
|
|
15
16
|
export declare const createAppProxy: (app: Application) => Application<import("./application").DefaultState, import("./application").DefaultContext>;
|
|
16
17
|
export declare const getCommandFullName: (command: Command) => string;
|
package/lib/helper.js
CHANGED
|
@@ -45,6 +45,7 @@ __export(helper_exports, {
|
|
|
45
45
|
getBodyLimit: () => getBodyLimit,
|
|
46
46
|
getCommandFullName: () => getCommandFullName,
|
|
47
47
|
registerMiddlewares: () => registerMiddlewares,
|
|
48
|
+
resolveCorsOrigin: () => resolveCorsOrigin,
|
|
48
49
|
tsxRerunning: () => tsxRerunning
|
|
49
50
|
});
|
|
50
51
|
module.exports = __toCommonJS(helper_exports);
|
|
@@ -76,23 +77,25 @@ function createResourcer(options) {
|
|
|
76
77
|
return new import_resourcer.Resourcer({ ...options.resourcer });
|
|
77
78
|
}
|
|
78
79
|
__name(createResourcer, "createResourcer");
|
|
80
|
+
function isWhitelistedCorsOrigin(ctx) {
|
|
81
|
+
const origin = ctx.get("origin");
|
|
82
|
+
if (!origin) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return (0, import_utils.isTrustedOrigin)(ctx, origin);
|
|
86
|
+
}
|
|
87
|
+
__name(isWhitelistedCorsOrigin, "isWhitelistedCorsOrigin");
|
|
79
88
|
function resolveCorsOrigin(ctx) {
|
|
80
89
|
const origin = ctx.get("origin");
|
|
81
90
|
const disallowNoOrigin = process.env.CORS_DISALLOW_NO_ORIGIN === "true";
|
|
82
|
-
const
|
|
91
|
+
const whitelist = (0, import_utils.getCorsWhitelist)();
|
|
83
92
|
if (!origin && disallowNoOrigin) {
|
|
84
93
|
return false;
|
|
85
94
|
}
|
|
86
|
-
if (
|
|
95
|
+
if (isWhitelistedCorsOrigin(ctx)) {
|
|
87
96
|
return origin;
|
|
88
97
|
}
|
|
89
|
-
|
|
90
|
-
whitelistString.split(",").map((item) => item.trim()).filter(Boolean)
|
|
91
|
-
);
|
|
92
|
-
if (whitelist.has(origin)) {
|
|
93
|
-
return origin;
|
|
94
|
-
}
|
|
95
|
-
return false;
|
|
98
|
+
return whitelist ? false : origin;
|
|
96
99
|
}
|
|
97
100
|
__name(resolveCorsOrigin, "resolveCorsOrigin");
|
|
98
101
|
function registerMiddlewares(app, options) {
|
|
@@ -108,7 +111,8 @@ function registerMiddlewares(app, options) {
|
|
|
108
111
|
app.use((0, import_logger.requestLogger)(app.name, app.requestLogger, (_a = options.logger) == null ? void 0 : _a.request), { tag: "logger" });
|
|
109
112
|
app.use(
|
|
110
113
|
(0, import_cors.default)({
|
|
111
|
-
|
|
114
|
+
credentials: isWhitelistedCorsOrigin,
|
|
115
|
+
exposeHeaders: ["content-disposition", "x-new-token"],
|
|
112
116
|
origin: resolveCorsOrigin,
|
|
113
117
|
...options.cors
|
|
114
118
|
}),
|
|
@@ -134,8 +138,20 @@ function registerMiddlewares(app, options) {
|
|
|
134
138
|
}
|
|
135
139
|
app.use(/* @__PURE__ */ __name(async function getBearerToken(ctx, next) {
|
|
136
140
|
ctx.getBearerToken = () => {
|
|
137
|
-
|
|
138
|
-
|
|
141
|
+
var _a2;
|
|
142
|
+
const authorization = ctx.get("Authorization");
|
|
143
|
+
if (authorization) {
|
|
144
|
+
ctx.state.pendingAuthTokenSource = "authorization";
|
|
145
|
+
return authorization.replace(/^Bearer\s+/gi, "");
|
|
146
|
+
}
|
|
147
|
+
if (ctx.query.token) {
|
|
148
|
+
ctx.state.pendingAuthTokenSource = "query";
|
|
149
|
+
return ctx.query.token;
|
|
150
|
+
}
|
|
151
|
+
const canUseAuthCookie = Boolean((_a2 = ctx.state) == null ? void 0 : _a2.fileAccess) && ["GET", "HEAD"].includes(ctx.method);
|
|
152
|
+
const cookieToken = canUseAuthCookie ? ctx.cookies.get((0, import_utils.getAuthCookieName)("authToken", app.name)) : void 0;
|
|
153
|
+
ctx.state.pendingAuthTokenSource = cookieToken ? "cookie" : void 0;
|
|
154
|
+
return cookieToken;
|
|
139
155
|
};
|
|
140
156
|
await next();
|
|
141
157
|
}, "getBearerToken"));
|
|
@@ -309,5 +325,6 @@ __name(createContextVariablesScope, "createContextVariablesScope");
|
|
|
309
325
|
getBodyLimit,
|
|
310
326
|
getCommandFullName,
|
|
311
327
|
registerMiddlewares,
|
|
328
|
+
resolveCorsOrigin,
|
|
312
329
|
tsxRerunning
|
|
313
330
|
});
|
package/lib/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from './gateway/ws-server';
|
|
|
13
13
|
export { Application as default } from './application';
|
|
14
14
|
export * from './audit-manager';
|
|
15
15
|
export * from './gateway';
|
|
16
|
+
export * from './gateway/static-file-security';
|
|
16
17
|
export * as middlewares from './middlewares';
|
|
17
18
|
export * from './migration';
|
|
18
19
|
export * from './plugin';
|
package/lib/index.js
CHANGED
|
@@ -55,6 +55,7 @@ __reExport(src_exports, require("./gateway/ws-server"), module.exports);
|
|
|
55
55
|
var import_application = require("./application");
|
|
56
56
|
__reExport(src_exports, require("./audit-manager"), module.exports);
|
|
57
57
|
__reExport(src_exports, require("./gateway"), module.exports);
|
|
58
|
+
__reExport(src_exports, require("./gateway/static-file-security"), module.exports);
|
|
58
59
|
var middlewares = __toESM(require("./middlewares"));
|
|
59
60
|
__reExport(src_exports, require("./migration"), module.exports);
|
|
60
61
|
__reExport(src_exports, require("./plugin"), module.exports);
|
|
@@ -85,6 +86,7 @@ var import_helper = require("./helper");
|
|
|
85
86
|
...require("./gateway/ws-server"),
|
|
86
87
|
...require("./audit-manager"),
|
|
87
88
|
...require("./gateway"),
|
|
89
|
+
...require("./gateway/static-file-security"),
|
|
88
90
|
...require("./migration"),
|
|
89
91
|
...require("./plugin"),
|
|
90
92
|
...require("./plugin-manager"),
|
package/lib/swagger/app.d.ts
CHANGED
|
@@ -12,7 +12,23 @@ declare const _default: {
|
|
|
12
12
|
readonly tags: readonly ["app"];
|
|
13
13
|
readonly summary: "Get the current application language";
|
|
14
14
|
readonly description: "Return the current locale used by the server.";
|
|
15
|
-
readonly parameters: readonly [
|
|
15
|
+
readonly parameters: readonly [{
|
|
16
|
+
readonly name: "locale";
|
|
17
|
+
readonly in: "query";
|
|
18
|
+
readonly required: false;
|
|
19
|
+
readonly schema: {
|
|
20
|
+
readonly type: "string";
|
|
21
|
+
};
|
|
22
|
+
readonly description: "Requested application locale. The server validates it against enabled languages.";
|
|
23
|
+
}, {
|
|
24
|
+
readonly name: "ns";
|
|
25
|
+
readonly in: "query";
|
|
26
|
+
readonly required: false;
|
|
27
|
+
readonly schema: {
|
|
28
|
+
readonly type: "string";
|
|
29
|
+
};
|
|
30
|
+
readonly description: "Comma-separated resource namespaces to return. Omit it to preserve the full legacy payload.";
|
|
31
|
+
}];
|
|
16
32
|
readonly responses: {
|
|
17
33
|
readonly 200: {
|
|
18
34
|
readonly description: "OK";
|
package/lib/swagger/app.js
CHANGED
|
@@ -35,7 +35,22 @@ var app_default = {
|
|
|
35
35
|
tags: ["app"],
|
|
36
36
|
summary: "Get the current application language",
|
|
37
37
|
description: "Return the current locale used by the server.",
|
|
38
|
-
parameters: [
|
|
38
|
+
parameters: [
|
|
39
|
+
{
|
|
40
|
+
name: "locale",
|
|
41
|
+
in: "query",
|
|
42
|
+
required: false,
|
|
43
|
+
schema: { type: "string" },
|
|
44
|
+
description: "Requested application locale. The server validates it against enabled languages."
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "ns",
|
|
48
|
+
in: "query",
|
|
49
|
+
required: false,
|
|
50
|
+
schema: { type: "string" },
|
|
51
|
+
description: "Comma-separated resource namespaces to return. Omit it to preserve the full legacy payload."
|
|
52
|
+
}
|
|
53
|
+
],
|
|
39
54
|
responses: {
|
|
40
55
|
200: {
|
|
41
56
|
description: "OK",
|
package/lib/swagger/index.d.ts
CHANGED
|
@@ -694,7 +694,23 @@ declare const _default: {
|
|
|
694
694
|
readonly tags: readonly ["app"];
|
|
695
695
|
readonly summary: "Get the current application language";
|
|
696
696
|
readonly description: "Return the current locale used by the server.";
|
|
697
|
-
readonly parameters: readonly [
|
|
697
|
+
readonly parameters: readonly [{
|
|
698
|
+
readonly name: "locale";
|
|
699
|
+
readonly in: "query";
|
|
700
|
+
readonly required: false;
|
|
701
|
+
readonly schema: {
|
|
702
|
+
readonly type: "string";
|
|
703
|
+
};
|
|
704
|
+
readonly description: "Requested application locale. The server validates it against enabled languages.";
|
|
705
|
+
}, {
|
|
706
|
+
readonly name: "ns";
|
|
707
|
+
readonly in: "query";
|
|
708
|
+
readonly required: false;
|
|
709
|
+
readonly schema: {
|
|
710
|
+
readonly type: "string";
|
|
711
|
+
};
|
|
712
|
+
readonly description: "Comma-separated resource namespaces to return. Omit it to preserve the full legacy payload.";
|
|
713
|
+
}];
|
|
698
714
|
readonly responses: {
|
|
699
715
|
readonly 200: {
|
|
700
716
|
readonly description: "OK";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/server",
|
|
3
|
-
"version": "2.2.0
|
|
3
|
+
"version": "2.2.0",
|
|
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.2.0
|
|
14
|
-
"@nocobase/actions": "2.2.0
|
|
15
|
-
"@nocobase/ai": "2.2.0
|
|
16
|
-
"@nocobase/auth": "2.2.0
|
|
17
|
-
"@nocobase/cache": "2.2.0
|
|
18
|
-
"@nocobase/data-source-manager": "2.2.0
|
|
19
|
-
"@nocobase/database": "2.2.0
|
|
20
|
-
"@nocobase/evaluators": "2.2.0
|
|
21
|
-
"@nocobase/lock-manager": "2.2.0
|
|
22
|
-
"@nocobase/logger": "2.2.0
|
|
23
|
-
"@nocobase/resourcer": "2.2.0
|
|
24
|
-
"@nocobase/sdk": "2.2.0
|
|
25
|
-
"@nocobase/snowflake-id": "2.2.0
|
|
26
|
-
"@nocobase/telemetry": "2.2.0
|
|
27
|
-
"@nocobase/utils": "2.2.0
|
|
13
|
+
"@nocobase/acl": "2.2.0",
|
|
14
|
+
"@nocobase/actions": "2.2.0",
|
|
15
|
+
"@nocobase/ai": "2.2.0",
|
|
16
|
+
"@nocobase/auth": "2.2.0",
|
|
17
|
+
"@nocobase/cache": "2.2.0",
|
|
18
|
+
"@nocobase/data-source-manager": "2.2.0",
|
|
19
|
+
"@nocobase/database": "2.2.0",
|
|
20
|
+
"@nocobase/evaluators": "2.2.0",
|
|
21
|
+
"@nocobase/lock-manager": "2.2.0",
|
|
22
|
+
"@nocobase/logger": "2.2.0",
|
|
23
|
+
"@nocobase/resourcer": "2.2.0",
|
|
24
|
+
"@nocobase/sdk": "2.2.0",
|
|
25
|
+
"@nocobase/snowflake-id": "2.2.0",
|
|
26
|
+
"@nocobase/telemetry": "2.2.0",
|
|
27
|
+
"@nocobase/utils": "2.2.0",
|
|
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": "
|
|
64
|
+
"gitHead": "d5052cae37177054c236f1bf7bba3aed6ef029d0"
|
|
65
65
|
}
|