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 {
|
export class AppManager {
|
||||||
public applications: Map<string, Application> = new Map<string, Application>();
|
public applications: Map<string, Application> = new Map<string, Application>();
|
||||||
public app: Application;
|
public app: Application;
|
||||||
|
public runningMode: 'single' | 'multiple' = 'multiple';
|
||||||
|
public singleAppName: string | null = null;
|
||||||
|
|
||||||
constructor(app: Application) {
|
constructor(app: Application) {
|
||||||
this.bindMainApplication(app);
|
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) {
|
bindMainApplication(mainApp: Application) {
|
||||||
@ -72,7 +80,12 @@ export class AppManager {
|
|||||||
return async (req: IncomingMessage, res: ServerResponse) => {
|
return async (req: IncomingMessage, res: ServerResponse) => {
|
||||||
const appManager = this.app.appManager;
|
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') {
|
if (typeof handleApp === 'string') {
|
||||||
handleApp = await appManager.getApplication(handleApp);
|
handleApp = await appManager.getApplication(handleApp);
|
||||||
|
@ -177,10 +177,22 @@ export class PluginMultiAppManager extends Plugin {
|
|||||||
|
|
||||||
this.app.on('afterUpgrade', async (app, options) => {
|
this.app.on('afterUpgrade', async (app, options) => {
|
||||||
const cliArgs = options?.cliArgs;
|
const cliArgs = options?.cliArgs;
|
||||||
|
|
||||||
const repository = this.db.getRepository('applications');
|
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) {
|
for (const instance of instances) {
|
||||||
const subApp = await this.app.appManager.getApplication(instance.name, {
|
const subApp = await appManager.getApplication(instance.name, {
|
||||||
upgrading: true,
|
upgrading: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user