feat(plugin-multi-apps): expiration prompt

This commit is contained in:
chenos 2021-11-10 20:32:16 +08:00
parent f737226898
commit f555a64a2d

View File

@ -71,11 +71,15 @@ function createApp(opts) {
} }
app.plugin( app.plugin(
require(`@nocobase/plugin-client/${__filename.endsWith('.ts') ? 'src' : 'lib'}/server`).default, { require(`@nocobase/plugin-client/${
dist: path.resolve(process.cwd(), './dist'), __filename.endsWith('.ts') ? 'src' : 'lib'
importDemo: true, }/server`).default,
lang: process.env.APP_LANG || 'zh-CN', {
}); dist: path.resolve(process.cwd(), './dist'),
importDemo: true,
lang: process.env.APP_LANG || 'zh-CN',
},
);
return app; return app;
} }
@ -93,7 +97,16 @@ function multiApps({ getAppName }) {
where: { name: appName }, where: { name: appName },
}); });
if (!model) { if (!model) {
return next(); if (ctx.path.includes('app:getLang')) {
ctx.body = {
data: {
lang: process.env.APP_LANG || 'en-US',
},
};
} else {
ctx.body = 'Expired';
}
return;
} }
const apps = ctx.app['apps']; const apps = ctx.app['apps'];
if (!apps.has(appName)) { if (!apps.has(appName)) {
@ -193,20 +206,22 @@ export default {
}, },
], ],
}); });
this.app.middleware.unshift(multiApps({ this.app.middleware.unshift(
getAppName(ctx) { multiApps({
console.log('ctx.hostname', ctx.hostname); getAppName(ctx) {
const hostname = ctx.get('X-Hostname') || ctx.hostname; console.log('ctx.hostname', ctx.hostname);
if (!hostname) { const hostname = ctx.get('X-Hostname') || ctx.hostname;
return; if (!hostname) {
} return;
const keys = hostname.split('.'); }
if (keys.length < 4) { const keys = hostname.split('.');
return; if (keys.length < 4) {
} return;
return keys.shift(); }
}, return keys.shift();
})); },
}),
);
this.app.db.on('applications.afterCreate', async (model: Model) => { this.app.db.on('applications.afterCreate', async (model: Model) => {
const name = model.get('name'); const name = model.get('name');
(async () => { (async () => {
@ -214,7 +229,7 @@ export default {
const app = createApp({ const app = createApp({
name, name,
}); });
console.log('creating........') console.log('creating........');
await app.load(); await app.load();
await app.db.sync({ await app.db.sync({
force: true, force: true,
@ -252,7 +267,7 @@ export default {
const app = createApp({ const app = createApp({
name, name,
}); });
console.log('creating........') console.log('creating........');
await app.load(); await app.load();
await app.db.sync({ await app.db.sync({
force: true, force: true,