Skip to content

Commit 9bed0ae

Browse files
committed
Decouple sdk constants from common env
1 parent b1f6bd2 commit 9bed0ae

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

sdk/src/constants.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,34 @@
1-
import { env, IS_DEV, IS_TEST, IS_PROD } from '@codebuff/common/env'
2-
3-
export { IS_DEV, IS_TEST, IS_PROD }
1+
const ENV = process.env.NEXT_PUBLIC_CB_ENVIRONMENT ?? 'dev'
2+
export const IS_DEV = ENV === 'dev'
3+
export const IS_TEST = ENV === 'test'
4+
export const IS_PROD = ENV === 'prod'
45

56
export const CODEBUFF_BINARY = 'codebuff'
67

7-
export const WEBSITE_URL = env.NEXT_PUBLIC_CODEBUFF_APP_URL
8+
const WEBSITE_URL_ENV = process.env.NEXT_PUBLIC_CODEBUFF_APP_URL
9+
export const WEBSITE_URL =
10+
WEBSITE_URL_ENV && WEBSITE_URL_ENV.length > 0
11+
? WEBSITE_URL_ENV
12+
: 'https://app.codebuff.com'
13+
14+
const DEFAULT_BACKEND_URL = 'manicode-backend.onrender.com'
15+
const DEFAULT_BACKEND_URL_DEV = 'localhost:4242'
16+
function isLocalhost(url: string) {
17+
return url.includes('localhost') || url.includes('127.0.0.1')
18+
}
19+
20+
function getWebsocketUrl(url: string) {
21+
return isLocalhost(url) ? `ws://${url}/ws` : `wss://${url}/ws`
22+
}
23+
export const WEBSOCKET_URL = getWebsocketUrl(
24+
process.env.NEXT_PUBLIC_CODEBUFF_BACKEND_URL ||
25+
(IS_PROD ? DEFAULT_BACKEND_URL : DEFAULT_BACKEND_URL_DEV),
26+
)
27+
28+
function getBackendUrl(url: string) {
29+
return isLocalhost(url) ? `http://${url}` : `https://${url}`
30+
}
31+
export const BACKEND_URL = getBackendUrl(
32+
process.env.NEXT_PUBLIC_CODEBUFF_BACKEND_URL ||
33+
(IS_PROD ? DEFAULT_BACKEND_URL : DEFAULT_BACKEND_URL_DEV),
34+
)

0 commit comments

Comments
 (0)