diff --git a/app.py b/app.py index ec1e6deebeaa2a7a22d501bcbe79192f568ea4f7..4031c8edd75b94c9625206cb66be981f356a0443 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 2ca032bac6ce1334c2248ba70b53e8a16a84d635..d3870f326add5a4bc632a24f24931280509ff862 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 ac535efa9e7dfd5a04f46fdb105a118c8ca900d0..d73046993d213e40bf415788c061f23e1c19f18a 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 9c785d4e958aed338d734475e2b7d7d787b5b77b..b3053c3d2f99dd23997d86dc69164561ec655a1d 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))