Skip to content

Commit ddce0e7

Browse files
authored
Merge pull request #20 from topcoder-platform/develop
Better prod fallback
2 parents dceac79 + 03b008a commit ddce0e7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/shared/util/common.utils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,26 @@ export class CommonUtils {
9595
}
9696
return result;
9797
}
98+
99+
/**
100+
* Resolve the Topcoder application domain from configuration with safe fallbacks.
101+
* @param configService Nest config service (or look-alike) used to read env config
102+
* @returns application domain such as topcoder-dev.com
103+
*/
104+
static getAppDomain(
105+
configService?: { get<T = any>(key: string): T | undefined },
106+
): string {
107+
const envDomain = process.env.APP_DOMAIN;
108+
if (envDomain && envDomain.trim().length > 0) {
109+
return envDomain.trim();
110+
}
111+
112+
// Fallback to topcoder.com for prod, if APP_DOMAIN isn't set
113+
const nodeEnv = process.env.NODE_ENV?.toLowerCase();
114+
if (nodeEnv === 'prod' || nodeEnv === 'production') {
115+
return 'topcoder.com';
116+
}
117+
118+
return 'topcoder-dev.com';
119+
}
98120
}

0 commit comments

Comments
 (0)