File size: 1,036 Bytes
0077b3c
19988fb
0077b3c
19988fb
0077b3c
 
 
19988fb
 
 
0077b3c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19988fb
 
 
 
 
 
 
 
 
0077b3c
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)