From d79a6489b3c054cc3b6b81192251bac19ccc3aa6 Mon Sep 17 00:00:00 2001 From: youhuo Date: Wed, 17 Aug 2022 18:08:43 +0800 Subject: [PATCH] feat: add front files --- app.py | 1 + app/setting.py | 10 +++++----- services/case_service.py | 4 ++-- views/common_view.py | 25 ++++++++++--------------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/app.py b/app.py index ec1e6de..4031c8e 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,6 @@ from app import app if __name__ == '__main__': + app.static('/static', 'dist') app.run(app.config['HOST'], app.config['PORT'], debug=app.config['DEBUG'], access_log=app.config['ACCESS_LOG'], workers=app.config['WORKERS'], auto_reload=app.config['AUTO_RELOAD']) diff --git a/app/setting.py b/app/setting.py index 2ca032b..d3870f3 100644 --- a/app/setting.py +++ b/app/setting.py @@ -2,12 +2,12 @@ import os BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "../")) -STATIC_URL = '/static/static/' +STATIC_URL = '/dist/dist/' STATICFILES_DIRS = ( - os.path.join(BASE_DIR, 'static/'), + os.path.join(BASE_DIR, 'dist/'), ) -STATIC_ROOT = os.path.join(BASE_DIR, '/static/').replace('\\', '/') +STATIC_ROOT = os.path.join(BASE_DIR, '/dist/').replace('\\', '/') -MEDIA_URL = '/static/media/' -MEDIA_ROOT = os.path.join(BASE_DIR, 'static/media/').replace('\\', '/') +MEDIA_URL = '/dist/media/' +MEDIA_ROOT = os.path.join(BASE_DIR, 'dist/media/').replace('\\', '/') OFFLINE_DATA_DIR = 'offline_data' diff --git a/services/case_service.py b/services/case_service.py index ac535ef..d730469 100644 --- a/services/case_service.py +++ b/services/case_service.py @@ -359,7 +359,7 @@ async def import_yaml(file_body, file_name): async def import_tar(file_body, file_name): - file_name = 'common/static/' + file_name + file_name = 'common/dist/' + file_name open(file_name, 'wb').write(file_body) tar_file = tarfile.open(file_name, 'r') for file_info in tar_file.getmembers(): @@ -590,7 +590,7 @@ def __get_priority(pr): async def excel_template(): - filepath = 'common/static/temp.xlsx' + filepath = 'common/dist/temp.xlsx' with open(filepath, "rb") as f: content = f.read() return content diff --git a/views/common_view.py b/views/common_view.py index 9c785d4..b3053c3 100644 --- a/views/common_view.py +++ b/views/common_view.py @@ -1,8 +1,6 @@ -from sanic import Blueprint +from sanic import Blueprint, response, html from sanic.exceptions import NotFound -from sanic.response import html -from app.conf import conf from common.http import rsp, http_request from services.auth_service import login_auth from services.common_service import upload_static_file_to_oss @@ -18,19 +16,16 @@ async def upload_images(request, user_infos): return rsp(data=result) -@bp.get('/') -async def index(request): - oss = conf.config['OSS_URL'] + '/' + request.app.name + '/' + conf.config['FRONT_VERSION'] - url = oss + '/index.html' - _, res = await http_request(url, 'get') - res = res.replace('', f'') - return html(res.replace(conf.config['REPLACE_DATA'], oss)) +@bp.exception(NotFound) +async def ignore_404s(request, exception): + return response.text("404. Oops, That page couldn't found.") -@bp.exception(NotFound) -async def handle_404_redirect(request, exception): - oss = conf.config['OSS_URL'] + '/' + request.app.name + '/' + conf.config['FRONT_VERSION'] +@bp.route('/') +async def handle_request(request): + oss = 'http://0.0.0.0:8005/static/' url = oss + '/index.html' _, res = await http_request(url, 'get') - res = res.replace('', f'') - return html(res.replace(conf.config['REPLACE_DATA'], oss)) + res = res.replace('', '') + print(res) + return html(res.replace('{OPENANOLIS_TEST_LIB_TOOLS_SERVER}', oss)) -- Gitee