Skip to content

Commit f7a529f

Browse files
authored
refactor(core): introduce new env for multiple custom domains feature (#7771)
1 parent 23467d9 commit f7a529f

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

packages/core/src/routes/domain.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ describe('domain routes', () => {
7272
expect(response.body.domain).toEqual('test.com');
7373
});
7474

75-
it('POST /domains allows creating multiple domains', async () => {
76-
const response = await domainRequest.post('/domains').send({ domain: 'another.com' });
77-
expect(response.status).toEqual(201);
78-
expect(addDomain).toBeCalledWith('another.com');
75+
it('POST /domains should fail when there is already a domain', async () => {
76+
await expect(
77+
domainRequest.post('/domains').send({ domain: mockDomain.domain })
78+
).resolves.toHaveProperty('status', 422);
7979
});
8080

8181
it('DELETE /domains/:id', async () => {

packages/core/src/routes/domain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default function domainRoutes<T extends ManagementApiRouter>(
7777
status: [201, 422, 400],
7878
}),
7979
async (ctx, next) => {
80-
if (!EnvSet.values.isDevFeaturesEnabled) {
80+
if (!EnvSet.values.isMultipleCustomDomainsEnabled) {
8181
const existingDomains = await findAllDomains();
8282
assertThat(
8383
existingDomains.length === 0,

packages/integration-tests/src/tests/api/domains.test.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HTTPError } from 'ky';
22

33
import { createDomain, deleteDomain, getDomain, getDomains } from '#src/api/domain.js';
4-
import { devFeatureDisabledTest, devFeatureTest, generateDomain } from '#src/utils.js';
4+
import { generateDomain } from '#src/utils.js';
55

66
describe('domains', () => {
77
afterEach(async () => {
@@ -23,24 +23,13 @@ describe('domains', () => {
2323
expect(domain.domain).toBe(domainName);
2424
});
2525

26-
// Todo: @xiaoyijun [Multiple Custom Domains] Remove legacy tests
27-
devFeatureDisabledTest.it('should fail when already has a domain', async () => {
26+
it('should fail when already has a domain', async () => {
2827
await createDomain();
2928

3029
const response = await createDomain().catch((error: unknown) => error);
3130
expect(response instanceof HTTPError && response.response.status).toBe(422);
3231
});
3332

34-
// Todo: @xiaoyijun [Multiple Custom Domains] Remove legacy tests
35-
devFeatureTest.it('should create multiple domains', async () => {
36-
const first = await createDomain();
37-
const second = await createDomain();
38-
39-
expect(first.id).toBeTruthy();
40-
expect(second.id).toBeTruthy();
41-
expect(first.id).not.toEqual(second.id);
42-
});
43-
4433
it('should get domain detail successfully', async () => {
4534
const createdDomain = await createDomain();
4635
const domain = await getDomain(createdDomain.id);

packages/shared/src/node/env/GlobalValues.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ export default class GlobalValues {
9090
/** If the env explicitly indicates it's in the cloud environment. */
9191
public readonly isCloud = yes(getEnv('IS_CLOUD'));
9292

93+
/**
94+
* Indicates whether this Logto instance supports multiple custom domains.
95+
*
96+
* **NOTE: Only available to enterprise customers running private instances that need this feature.**
97+
*
98+
* Controlled by the `MULTIPLE_CUSTOM_DOMAINS_ENABLED` environment variable. When enabled, the instance
99+
* can operate with multiple custom domains across both development and production tenants.
100+
*/
101+
public readonly isMultipleCustomDomainsEnabled = yes(getEnv('MULTIPLE_CUSTOM_DOMAINS_ENABLED'));
102+
93103
// eslint-disable-next-line unicorn/consistent-function-scoping
94104
public readonly databaseUrl = tryThat(() => assertEnv('DB_URL'), throwErrorWithDsnMessage);
95105
public readonly developmentTenantId = getEnv('DEVELOPMENT_TENANT_ID');

0 commit comments

Comments
 (0)