File tree Expand file tree Collapse file tree 1 file changed +31
-3
lines changed
Expand file tree Collapse file tree 1 file changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -4,9 +4,37 @@ export const IS_DEV = process.env.NEXT_PUBLIC_CB_ENVIRONMENT === 'dev'
44export const IS_TEST = process . env . NEXT_PUBLIC_CB_ENVIRONMENT === 'test'
55export const IS_PROD = ! IS_DEV && ! IS_TEST
66
7- export const WEBSITE_URL =
8- process . env . NEXT_PUBLIC_CODEBUFF_APP_URL ||
9- ( IS_PROD ? 'https://codebuff.com' : 'http://localhost:3000' )
7+ const normalizeLocalWebPort = ( env : NodeJS . ProcessEnv ) : string => {
8+ const port = env . NEXT_PUBLIC_WEB_PORT
9+ if ( port && / ^ \d + $ / . test ( port ) ) {
10+ return port
11+ }
12+ return '3000'
13+ }
14+
15+ export const resolveWebsiteUrl = (
16+ env : NodeJS . ProcessEnv = process . env ,
17+ ) : string => {
18+ const explicitUrl = env . NEXT_PUBLIC_CODEBUFF_APP_URL
19+ if ( explicitUrl ) {
20+ return explicitUrl
21+ }
22+
23+ const envName = env . NEXT_PUBLIC_CB_ENVIRONMENT
24+ const isProdEnv =
25+ envName === undefined
26+ ? IS_PROD
27+ : envName !== 'dev' && envName !== 'test'
28+
29+ if ( isProdEnv ) {
30+ return 'https://codebuff.com'
31+ }
32+
33+ const port = normalizeLocalWebPort ( env )
34+ return `http://localhost:${ port } `
35+ }
36+
37+ export const WEBSITE_URL = resolveWebsiteUrl ( )
1038
1139const DEFAULT_BACKEND_URL = 'manicode-backend.onrender.com'
1240const DEFAULT_BACKEND_URL_DEV = 'localhost:4242'
You can’t perform that action at this time.
0 commit comments