import os import logging from flask import Flask, render_template from werkzeug.exceptions import HTTPException app = Flask(__name__) # Configure logging logging.basicConfig(level=logging.INFO) # 配置 Jinja2 分隔符,避免与 Vue 插值语法冲突 app.jinja_env.variable_start_string = '[[' app.jinja_env.variable_end_string = ']]' app.jinja_env.block_start_string = '[%' app.jinja_env.block_end_string = '%]' app.jinja_env.comment_start_string = '[#' app.jinja_env.comment_end_string = '#]' @app.route('/') def index(): return render_template('index.html') @app.route('/healthz') def healthz(): return "ok" @app.errorhandler(Exception) def handle_exception(e): # pass through HTTP errors if isinstance(e, HTTPException): return e # now you're handling non-HTTP exceptions only app.logger.error(f"Unhandled Exception: {e}", exc_info=True) return "Internal Server Error", 500 if __name__ == '__main__': port = int(os.environ.get('PORT', 7860)) app.run(host='0.0.0.0', port=port)