feat: support running single sub app (#1853)
This commit is contained in:
parent
ff6f37c589
commit
1c757bd025
@ -8,9 +8,17 @@ type AppSelector = (req: IncomingMessage) => AppSelectorReturn | Promise<AppSele
|
||||
export class AppManager {
|
||||
public applications: Map<string, Application> = new Map<string, Application>();
|
||||
public app: Application;
|
||||
public runningMode: 'single' | 'multiple' = 'multiple';
|
||||
public singleAppName: string | null = null;
|
||||
|
||||
constructor(app: Application) {
|
||||
this.bindMainApplication(app);
|
||||
|
||||
// if STARTUP_SUBAPP is set, run in single mode
|
||||
if (process.env.STARTUP_SUBAPP) {
|
||||
this.singleAppName = process.env.STARTUP_SUBAPP;
|
||||
this.runningMode = 'single';
|
||||
}
|
||||
}
|
||||
|
||||
bindMainApplication(mainApp: Application) {
|
||||
@ -72,7 +80,12 @@ export class AppManager {
|
||||
return async (req: IncomingMessage, res: ServerResponse) => {
|
||||
const appManager = this.app.appManager;
|
||||
|
||||
let handleApp: any = (await appManager.appSelector(req)) || appManager.app;
|
||||
let handleApp;
|
||||
if (this.runningMode === 'single') {
|
||||
handleApp = this.singleAppName;
|
||||
} else {
|
||||
handleApp = (await appManager.appSelector(req)) || appManager.app;
|
||||
}
|
||||
|
||||
if (typeof handleApp === 'string') {
|
||||
handleApp = await appManager.getApplication(handleApp);
|
||||
|
@ -177,10 +177,22 @@ export class PluginMultiAppManager extends Plugin {
|
||||
|
||||
this.app.on('afterUpgrade', async (app, options) => {
|
||||
const cliArgs = options?.cliArgs;
|
||||
|
||||
const repository = this.db.getRepository('applications');
|
||||
const instances = await repository.find();
|
||||
const findOptions = {};
|
||||
|
||||
const appManager = this.app.appManager;
|
||||
|
||||
if (appManager.runningMode == 'single') {
|
||||
findOptions['filter'] = {
|
||||
name: appManager.singleAppName,
|
||||
};
|
||||
}
|
||||
|
||||
const instances = await repository.find(findOptions);
|
||||
|
||||
for (const instance of instances) {
|
||||
const subApp = await this.app.appManager.getApplication(instance.name, {
|
||||
const subApp = await appManager.getApplication(instance.name, {
|
||||
upgrading: true,
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user