Skip to content

Commit a730d3a

Browse files
Evansyedram
andcommitted
chore(env): 支持环境多变量配置
--------- Co-authored-by: edram <[email protected]>
1 parent fa2a5a7 commit a730d3a

File tree

7 files changed

+15
-3
lines changed

7 files changed

+15
-3
lines changed

.env

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VITE_API_PREFIX=https://api.mallchat.cn
2+
VITE_WS_URL=wss://api.mallchat.cn/websocket

.env.production

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VITE_API_PREFIX=https://api.mallchat.cn
2+
VITE_WS_URL=wss://api.mallchat.cn/websocket

src/components.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ declare module '@vue/runtime-core' {
3535
IEpLock: typeof import('~icons/ep/lock')['default']
3636
IEpMale: typeof import('~icons/ep/male')['default']
3737
IEpSuccessFilled: typeof import('~icons/ep/success-filled')['default']
38+
LikeButton: typeof import('./components/LikeButton/index.vue')['default']
3839
LoginBox: typeof import('./components/LoginBox/index.vue')['default']
3940
RouterLink: typeof import('vue-router')['RouterLink']
4041
RouterView: typeof import('vue-router')['RouterView']

src/env.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
/// <reference types="vite/client" />
2+
3+
interface ImportMetaEnv {
4+
/** API 前缀 */
5+
readonly VITE_API_PREFIX: string
6+
/** WS 地址 */
7+
readonly VITE_WS_URL: string
8+
}

src/services/urls.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const prefix = import.meta.env.PROD ? 'https://api.mallchat.cn' : ''
1+
const prefix = import.meta.env.VITE_API_PREFIX
22
export default {
33
getGroupUserList: `${prefix}/capi/chat/public/member/page`,
44
getMemberStatistic: `${prefix}/capi/chat/public/member/statistic`,

src/utils/initWorker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const worker: Worker = new Worker(new URL('./worker.ts', import.meta.url))
1+
export const worker: Worker = new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' })

src/utils/worker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const initConnection = () => {
9393
connection?.removeEventListener('close', onConnectClose)
9494
connection?.removeEventListener('error', onConnectError)
9595
// 建立链接
96-
connection = new WebSocket('wss://api.mallchat.cn/websocket')
96+
connection = new WebSocket(import.meta.env.VITE_WS_URL)
9797
// 收到消息
9898
connection.addEventListener('message', onConnectMsg)
9999
// 建立链接

0 commit comments

Comments
 (0)