| | """静态文件路由""" |
| | from urllib.parse import unquote |
| | from flask import send_from_directory, redirect, abort, request |
| | from backend.access_log import log_page_load, log_demo_file |
| |
|
| |
|
| | def register_static_routes(app): |
| | """注册静态文件路由""" |
| | |
| | @app.route('/') |
| | def redir(): |
| | target = 'client/index.html' |
| | if request.query_string: |
| | target += '?' + request.query_string.decode() |
| | return redirect(target) |
| |
|
| | @app.route('/client/<path:path>') |
| | def send_static(path): |
| | """serves all files from ./client/ to ``/client/<path:path>`` |
| | |
| | :param path: path from api call |
| | """ |
| | |
| | if path.endswith('.html'): |
| | log_page_load(path) |
| | return send_from_directory('client/dist/', path) |
| |
|
| | @app.route('/demo/<path:path>') |
| | def send_demo(path): |
| | """serves all demo files from the demo dir to ``/demo/<path:path>`` |
| | |
| | :param path: path from api call |
| | """ |
| | from backend.app_context import get_data_dir |
| | data_dir = get_data_dir() |
| | |
| | |
| | log_demo_file(path) |
| | |
| | |
| | try: |
| | decoded_path = unquote(path) |
| | return send_from_directory(str(data_dir), decoded_path) |
| | except Exception as e: |
| | |
| | try: |
| | return send_from_directory(str(data_dir), path) |
| | except Exception: |
| | abort(404) |
| |
|
| |
|