15th_final and clean
This commit is contained in:
35
app.py
35
app.py
@@ -62,13 +62,30 @@ def test():
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
"""首頁路由"""
|
||||
return {
|
||||
'application': 'PANJIT Document Translator',
|
||||
'version': '1.0.0',
|
||||
'status': 'running',
|
||||
'api_base_url': '/api/v1'
|
||||
}
|
||||
"""首頁路由 - 服務前端應用"""
|
||||
try:
|
||||
from flask import send_from_directory
|
||||
return send_from_directory('/app/static', 'index.html')
|
||||
except Exception as e:
|
||||
# 如果靜態文件不存在,返回API信息
|
||||
return {
|
||||
'application': 'PANJIT Document Translator',
|
||||
'version': '1.0.0',
|
||||
'status': 'running',
|
||||
'api_base_url': '/api/v1',
|
||||
'note': 'Frontend files not found, serving API info'
|
||||
}
|
||||
|
||||
|
||||
@app.route('/<path:path>')
|
||||
def serve_static(path):
|
||||
"""服務靜態文件"""
|
||||
try:
|
||||
from flask import send_from_directory
|
||||
return send_from_directory('/app/static', path)
|
||||
except Exception:
|
||||
# 如果文件不存在,返回index.html (SPA路由)
|
||||
return send_from_directory('/app/static', 'index.html')
|
||||
|
||||
|
||||
@app.route('/api')
|
||||
@@ -102,9 +119,9 @@ def health_check():
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 檢查環境變數
|
||||
port = int(os.environ.get('PORT', 5000))
|
||||
port = int(os.environ.get('PORT', 12010))
|
||||
debug = os.environ.get('FLASK_DEBUG', 'false').lower() == 'true'
|
||||
host = os.environ.get('HOST', '127.0.0.1')
|
||||
host = os.environ.get('HOST', '0.0.0.0')
|
||||
|
||||
# 只在主進程或非 debug 模式下顯示啟動訊息
|
||||
# 在 debug 模式下,Flask 會創建兩個進程,只在 reloader 主進程顯示訊息
|
||||
|
Reference in New Issue
Block a user