refactor(domain-manager): simplify frontend URL configuration (#10194)
Replaced multiple environment variables for frontend URL construction with a single FRONTEND_URL variable. This change reduces complexity and improves clarity by consolidating frontend URL handling into one source. Updated relevant validations and removed unused variables like FRONT_PROTOCOL and FRONT_PORT. Fix #10016
This commit is contained in:
@ -15,8 +15,7 @@ describe('DomainManagerService', () => {
|
||||
.spyOn(environmentService, 'get')
|
||||
.mockImplementation((key: string) => {
|
||||
const env = {
|
||||
FRONT_PROTOCOL: 'https',
|
||||
FRONT_DOMAIN: 'example.com',
|
||||
FRONTEND_URL: 'https://example.com',
|
||||
};
|
||||
|
||||
return env[key];
|
||||
@ -39,8 +38,7 @@ describe('DomainManagerService', () => {
|
||||
.spyOn(environmentService, 'get')
|
||||
.mockImplementation((key: string) => {
|
||||
const env = {
|
||||
FRONT_PROTOCOL: 'https',
|
||||
FRONT_DOMAIN: 'example.com',
|
||||
FRONTEND_URL: 'https://example.com',
|
||||
};
|
||||
|
||||
return env[key];
|
||||
@ -84,13 +82,12 @@ describe('DomainManagerService', () => {
|
||||
});
|
||||
|
||||
describe('buildBaseUrl', () => {
|
||||
it('should build the base URL with protocol and domain from environment variables', () => {
|
||||
it('should build the base URL from environment variables', () => {
|
||||
jest
|
||||
.spyOn(environmentService, 'get')
|
||||
.mockImplementation((key: string) => {
|
||||
const env = {
|
||||
FRONT_PROTOCOL: 'https',
|
||||
FRONT_DOMAIN: 'example.com',
|
||||
FRONTEND_URL: 'https://example.com',
|
||||
};
|
||||
|
||||
return env[key];
|
||||
@ -106,8 +103,8 @@ describe('DomainManagerService', () => {
|
||||
.spyOn(environmentService, 'get')
|
||||
.mockImplementation((key: string) => {
|
||||
const env = {
|
||||
FRONT_PROTOCOL: 'https',
|
||||
FRONT_DOMAIN: 'example.com',
|
||||
FRONTEND_URL: 'https://example.com',
|
||||
|
||||
IS_MULTIWORKSPACE_ENABLED: true,
|
||||
DEFAULT_SUBDOMAIN: 'test',
|
||||
};
|
||||
@ -119,24 +116,6 @@ describe('DomainManagerService', () => {
|
||||
|
||||
expect(result.toString()).toBe('https://test.example.com/');
|
||||
});
|
||||
|
||||
it('should append port if FRONT_PORT is set', () => {
|
||||
jest
|
||||
.spyOn(environmentService, 'get')
|
||||
.mockImplementation((key: string) => {
|
||||
const env = {
|
||||
FRONT_PROTOCOL: 'https',
|
||||
FRONT_DOMAIN: 'example.com',
|
||||
FRONT_PORT: '8080',
|
||||
};
|
||||
|
||||
return env[key];
|
||||
});
|
||||
|
||||
const result = domainManagerService.getBaseUrl();
|
||||
|
||||
expect(result.toString()).toBe('https://example.com:8080/');
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildWorkspaceURL', () => {
|
||||
@ -145,8 +124,8 @@ describe('DomainManagerService', () => {
|
||||
.spyOn(environmentService, 'get')
|
||||
.mockImplementation((key: string) => {
|
||||
const env = {
|
||||
FRONT_PROTOCOL: 'https',
|
||||
FRONT_DOMAIN: 'example.com',
|
||||
FRONTEND_URL: 'https://example.com',
|
||||
|
||||
IS_MULTIWORKSPACE_ENABLED: true,
|
||||
DEFAULT_SUBDOMAIN: 'default',
|
||||
};
|
||||
@ -170,8 +149,7 @@ describe('DomainManagerService', () => {
|
||||
.spyOn(environmentService, 'get')
|
||||
.mockImplementation((key: string) => {
|
||||
const env = {
|
||||
FRONT_PROTOCOL: 'https',
|
||||
FRONT_DOMAIN: 'example.com',
|
||||
FRONTEND_URL: 'https://example.com',
|
||||
};
|
||||
|
||||
return env[key];
|
||||
@ -194,8 +172,7 @@ describe('DomainManagerService', () => {
|
||||
.spyOn(environmentService, 'get')
|
||||
.mockImplementation((key: string) => {
|
||||
const env = {
|
||||
FRONT_PROTOCOL: 'https',
|
||||
FRONT_DOMAIN: 'example.com',
|
||||
FRONTEND_URL: 'https://example.com',
|
||||
};
|
||||
|
||||
return env[key];
|
||||
|
||||
@ -21,28 +21,10 @@ export class DomainManagerService {
|
||||
) {}
|
||||
|
||||
getFrontUrl() {
|
||||
let baseUrl: URL;
|
||||
const frontPort = this.environmentService.get('FRONT_PORT');
|
||||
const frontDomain = this.environmentService.get('FRONT_DOMAIN');
|
||||
const frontProtocol = this.environmentService.get('FRONT_PROTOCOL');
|
||||
|
||||
const serverUrl = this.environmentService.get('SERVER_URL');
|
||||
|
||||
if (!frontDomain) {
|
||||
baseUrl = new URL(serverUrl);
|
||||
} else {
|
||||
baseUrl = new URL(`${frontProtocol}://${frontDomain}`);
|
||||
}
|
||||
|
||||
if (frontPort) {
|
||||
baseUrl.port = frontPort.toString();
|
||||
}
|
||||
|
||||
if (frontProtocol) {
|
||||
baseUrl.protocol = frontProtocol;
|
||||
}
|
||||
|
||||
return baseUrl;
|
||||
return new URL(
|
||||
this.environmentService.get('FRONTEND_URL') ??
|
||||
this.environmentService.get('SERVER_URL'),
|
||||
);
|
||||
}
|
||||
|
||||
getBaseUrl(): URL {
|
||||
|
||||
@ -551,11 +551,11 @@ export class EnvironmentVariables {
|
||||
|
||||
@EnvironmentVariablesMetadata({
|
||||
group: EnvironmentVariablesGroup.ServerConfig,
|
||||
description: 'Domain for the frontend application',
|
||||
description: 'Url for the frontend application',
|
||||
})
|
||||
@IsString()
|
||||
@IsUrl({ require_tld: false, require_protocol: true })
|
||||
@IsOptional()
|
||||
FRONT_DOMAIN?: string;
|
||||
FRONTEND_URL: string;
|
||||
|
||||
@EnvironmentVariablesMetadata({
|
||||
group: EnvironmentVariablesGroup.ServerConfig,
|
||||
@ -566,23 +566,6 @@ export class EnvironmentVariables {
|
||||
@ValidateIf((env) => env.IS_MULTIWORKSPACE_ENABLED)
|
||||
DEFAULT_SUBDOMAIN = 'app';
|
||||
|
||||
@EnvironmentVariablesMetadata({
|
||||
group: EnvironmentVariablesGroup.ServerConfig,
|
||||
description: 'Protocol for the frontend application (http or https)',
|
||||
})
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
FRONT_PROTOCOL?: 'http' | 'https' = 'http';
|
||||
|
||||
@EnvironmentVariablesMetadata({
|
||||
group: EnvironmentVariablesGroup.ServerConfig,
|
||||
description: 'Port for the frontend application',
|
||||
})
|
||||
@CastToPositiveNumber()
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
FRONT_PORT?: number;
|
||||
|
||||
@EnvironmentVariablesMetadata({
|
||||
group: EnvironmentVariablesGroup.Other,
|
||||
description: 'ID for the Chrome extension',
|
||||
|
||||
Reference in New Issue
Block a user