From 7cfa94c68c761874762f3fa0a9eb785631b1fff2 Mon Sep 17 00:00:00 2001 From: John Smith Date: Wed, 19 Aug 2020 23:16:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9API=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- frontend/src/views/Home.vue | 2 +- frontend/src/views/Room.vue | 2 +- main.py | 4 ++++ 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 60a50fe..987d8be 100644 --- a/README.md +++ b/README.md @@ -111,11 +111,11 @@ server { try_files $uri $uri/ /index.html; } # 动态API - location = /server_info { + location /api { proxy_pass http://blivechat; } # websocket - location = /chat { + location = /api/chat { proxy_pass http://blivechat; # 代理websocket必须设置 diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue index c31b9e0..a6a9160 100644 --- a/frontend/src/views/Home.vue +++ b/frontend/src/views/Home.vue @@ -129,7 +129,7 @@ export default { methods: { async updateServerConfig() { try { - this.serverConfig = (await axios.get(`/server_info`)).data.config + this.serverConfig = (await axios.get('/api/server_info')).data.config } catch (e) { this.$message.error('Failed to fetch server information: ' + e) } diff --git a/frontend/src/views/Room.vue b/frontend/src/views/Room.vue index 77f35ae..f31c7d7 100644 --- a/frontend/src/views/Room.vue +++ b/frontend/src/views/Room.vue @@ -84,7 +84,7 @@ export default { const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws' // 开发时使用localhost:12450 const host = process.env.NODE_ENV === 'development' ? 'localhost:12450' : window.location.host - const url = `${protocol}://${host}/chat` + const url = `${protocol}://${host}/api/chat` this.websocket = new WebSocket(url) this.websocket.onopen = this.onWsOpen this.websocket.onclose = this.onWsClose diff --git a/main.py b/main.py index 1190e6b..190544a 100644 --- a/main.py +++ b/main.py @@ -21,6 +21,10 @@ logger = logging.getLogger(__name__) WEB_ROOT = os.path.join(os.path.dirname(__file__), 'frontend', 'dist') routes = [ + (r'/api/server_info', api.main.ServerInfoHandler), + (r'/api/chat', api.chat.ChatHandler), + + # TODO 兼容旧版,下版本移除 (r'/server_info', api.main.ServerInfoHandler), (r'/chat', api.chat.ChatHandler),