0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-20 21:32:31 -05:00

refactor(core): optimize tenant middleware function

This commit is contained in:
Gao Sun 2023-03-13 15:52:38 +08:00
parent 3e9ba19fa2
commit 9db5729cfd
No known key found for this signature in database
GPG key ID: 13EBE123E4773688

View file

@ -40,20 +40,9 @@ export default class Tenant implements TenantContext {
public readonly provider: Provider;
public readonly queries: Queries;
public readonly libraries: Libraries;
public readonly run: MiddlewareType;
public readonly app: Koa;
get run(): MiddlewareType {
if (
EnvSet.values.isPathBasedMultiTenancy &&
// If admin URL Set is specified, consider that URL first
!(EnvSet.values.adminUrlSet.deduplicated().length > 0 && this.id === adminTenantId)
) {
return mount('/' + this.id, this.app);
}
return mount(this.app);
}
private readonly app: Koa;
private constructor(public readonly envSet: EnvSet, public readonly id: string) {
const queries = new Queries(envSet.pool);
@ -132,6 +121,14 @@ export default class Tenant implements TenantContext {
this.app = app;
this.provider = provider;
const { isPathBasedMultiTenancy, adminUrlSet } = EnvSet.values;
this.run =
isPathBasedMultiTenancy &&
// If admin URL Set is specified, consider that URL first
!(adminUrlSet.deduplicated().length > 0 && this.id === adminTenantId)
? mount('/' + this.id, this.app)
: mount(this.app);
}
public requestStart() {