Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/shared/util/common.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,26 @@ export class CommonUtils {
}
return result;
}

/**
* Resolve the Topcoder application domain from configuration with safe fallbacks.
* @param configService Nest config service (or look-alike) used to read env config
* @returns application domain such as topcoder-dev.com
*/
static getAppDomain(
configService?: { get<T = any>(key: string): T | undefined },
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ maintainability]
The configService parameter is defined but never used in the function. Consider removing it if it's not needed, or utilize it to fetch configuration values if intended.

): string {
const envDomain = process.env.APP_DOMAIN;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ design]
Accessing environment variables directly within the function can make testing more difficult. Consider passing the environment variables as parameters or using dependency injection to improve testability.

if (envDomain && envDomain.trim().length > 0) {
return envDomain.trim();
}

// Fallback to topcoder.com for prod, if APP_DOMAIN isn't set
const nodeEnv = process.env.NODE_ENV?.toLowerCase();
if (nodeEnv === 'prod' || nodeEnv === 'production') {
return 'topcoder.com';
}

return 'topcoder-dev.com';
}
}
Loading