fix: app manager reload (#1565)

* fix: app manager reload

* chore: plugin test order
This commit is contained in:
ChengLei Shao 2023-03-14 13:10:15 +08:00 committed by GitHub
parent 9c60402153
commit e86e40b93a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 5 deletions

View File

@ -33,6 +33,9 @@ export function getConfigByEnv() {
timezone: process.env.DB_TIMEZONE,
underscored: process.env.DB_UNDERSCORED === 'true',
schema: process.env.DB_SCHEMA !== 'public' ? process.env.DB_SCHEMA : undefined,
dialectOptions: {
application_name: process.env.DB_DIALECT == 'postgres' ? 'nocobase.main' : undefined,
},
};
}

View File

@ -9,12 +9,17 @@ type AppSelector = (req: IncomingMessage) => AppSelectorReturn | Promise<AppSele
export class AppManager extends EventEmitter {
public applications: Map<string, Application> = new Map<string, Application>();
public app: Application;
constructor(public app: Application) {
constructor(app: Application) {
super();
this.bindMainApplication(app);
}
bindMainApplication(mainApp: Application) {
this.app = mainApp;
const passEventToSubApps = (eventName, method) => {
app.on(eventName, async (mainApp, options) => {
mainApp.on(eventName, async (mainApp, options) => {
console.log(`receive event ${eventName} from ${mainApp.name}`);
for (const application of this.applications.values()) {
console.log(`pass ${eventName} to ${application.name} `);

View File

@ -271,7 +271,11 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
});
}
this._appManager = new AppManager(this);
if (this._appManager) {
this._appManager.bindMainApplication(this);
} else {
this._appManager = new AppManager(this);
}
if (this.options.acl !== false) {
this._resourcer.use(this._acl.middleware(), { tag: 'acl', after: ['parseToken'] });

View File

@ -90,7 +90,7 @@ pgOnly()('collection sync', () => {
expect(userInSub2.get('roles').map((item) => item.name)).toContain(defaultRoleInSub2.name);
});
it.skip('should sync plugin status between apps', async () => {
it('should sync plugin status between apps', async () => {
await mainApp.db.getRepository('applications').create({
values: {
name: 'sub1',

View File

@ -1,5 +1,6 @@
import PluginMultiAppManager from '@nocobase/plugin-multi-app-manager';
import { Application, InstallOptions, Plugin } from '@nocobase/server';
import lodash from 'lodash';
const subAppFilteredPlugins = ['multi-app-share-collection', 'multi-app-manager'];
@ -241,7 +242,11 @@ export class MultiAppShareCollectionPlugin extends Plugin {
);
return {
database: databaseOptions,
database: lodash.merge(databaseOptions, {
dialectOptions: {
application_name: `nocobase.${appName}`,
},
}),
plugins: plugins.includes('nocobase') ? ['nocobase'] : plugins,
resourcer: {
prefix: '/api',