From bfa605489909864a9ada9447f47e8179f265439c Mon Sep 17 00:00:00 2001 From: John Smith Date: Tue, 18 Aug 2020 21:48:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=9A=84=E6=88=BF=E9=97=B4UR?= =?UTF-8?q?L=E6=94=B9=E6=88=90=E5=8A=A0=E8=BD=BD=E5=99=A8URL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/main.py | 12 +++++++++--- frontend/src/views/Home.vue | 10 +++++++++- main.py | 4 +--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/api/main.py b/api/main.py index 1846619..bbe2716 100644 --- a/api/main.py +++ b/api/main.py @@ -8,9 +8,15 @@ import update class MainHandler(tornado.web.StaticFileHandler): - """为了使用Vue Router的history模式,把所有请求转发到index.html""" - async def get(self, *args, **kwargs): - await super().get('index.html', *args, **kwargs) + """为了使用Vue Router的history模式,把不存在的文件请求转发到index.html""" + async def get(self, path, include_body=True): + try: + await super().get(path, include_body) + except tornado.web.HTTPError as e: + if e.status_code != 404: + raise + # 不存在的文件请求转发到index.html,交给前端路由 + await super().get('index.html', include_body) # noinspection PyAbstractClass diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue index a05496b..c31b9e0 100644 --- a/frontend/src/views/Home.vue +++ b/frontend/src/views/Home.vue @@ -66,7 +66,7 @@ - + {{$t('home.copy')}} @@ -107,6 +107,14 @@ export default { delete query.roomId let resolved = this.$router.resolve({name: 'room', params: {roomId: this.form.roomId}, query}) return `${window.location.protocol}//${window.location.host}${resolved.href}` + }, + loaderUrl() { + if (this.roomUrl === '') { + return '' + } + let url = new URL('https://xfgryujk.sinacloud.net/blivechat/loader.html') + url.searchParams.append('url', this.roomUrl) + return url.href } }, watch: { diff --git a/main.py b/main.py index ad7db0e..1190e6b 100644 --- a/main.py +++ b/main.py @@ -24,9 +24,7 @@ routes = [ (r'/server_info', api.main.ServerInfoHandler), (r'/chat', api.chat.ChatHandler), - (r'/((css|fonts|img|js|static)/.*)', tornado.web.StaticFileHandler, {'path': WEB_ROOT}), - (r'/(favicon\.ico)', tornado.web.StaticFileHandler, {'path': WEB_ROOT}), - (r'/.*', api.main.MainHandler, {'path': WEB_ROOT}) + (r'/(.*)', api.main.MainHandler, {'path': WEB_ROOT, 'default_filename': 'index.html'}) ]