diff --git a/package.json b/package.json index a6cd46f..3198a09 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,8 @@ "test": "echo \"No test specified\" && exit 0", "dev": "quasar dev", "build": "quasar build", + "build:test": "set NODE_ENV=test&&quasar build", + "build:publish": "set NODE_ENV=publish&&quasar build", "protoc": "node scripts/proto.cjs", "sync": "node scripts/sync.cjs" }, diff --git a/quasar.config.js b/quasar.config.js index 3f02c23..7973526 100644 --- a/quasar.config.js +++ b/quasar.config.js @@ -52,6 +52,10 @@ module.exports = configure(function (/* ctx */) { // Full list of options: https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#build build: { + env: { + // test:测试服务器;publish:正式服务器;其他本地 + ENV_MODE: process.env.NODE_ENV, + }, target: { browser: ['es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1'], node: 'node16', diff --git a/src/configs/UrlManage.ts b/src/configs/UrlManage.ts index 73b2dcd..48def03 100644 --- a/src/configs/UrlManage.ts +++ b/src/configs/UrlManage.ts @@ -1,4 +1,9 @@ function getHost(): string { + if (process.env.ENV_MODE == 'test') { + return 'test.joylink.club/bjrtss-server'; + } else if (process.env.ENV_MODE == 'publish') { + return 'joylink.club/bjrtss-server'; + } // return '192.168.3.7:9091'; // return '192.168.3.47:9091'; // return '192.168.3.37:9091'; @@ -6,18 +11,28 @@ function getHost(): string { // return '192.168.3.5:9091'; // return '192.168.3.37:9091'; return '192.168.3.233:9091'; - // return 'test.joylink.club/bjrtss-server'; } export function getHttpBase() { - return `http://${getHost()}`; - // return `https://${getHost()}`; + let protocol = 'http'; + if (['test', 'publish'].includes(process.env.ENV_MODE as string)) { + protocol = 'https'; + } + return `${protocol}://${getHost()}`; } export function getWebsocketUrl() { - const host = '192.168.3.233'; - const port = 8000; - // return `ws://${host}/ws-bj`; - return `ws://${host}:${port}/connection/websocket`; - // return `wss://${getHost()}/ws-bj`; + let protocol = 'ws'; + let host = '192.168.3.233'; + let port = '8000'; + if (process.env.ENV_MODE == 'test') { + protocol = 'wss'; + host = 'test.joylink.club/bjrtss-server'; + port = ''; + } else if (process.env.ENV_MODE == 'publish') { + protocol = 'wss'; + host = 'joylink.club/bjrtss-server'; + port = ''; + } + return `${protocol}://${host}:${port}/connection/websocket`; }