"""
Flaskアプリ本体
役割:
- HTMLページを配信
- APIを提供
"""
from flask import Flask, render_template, jsonify, request
# Flaskアプリ生成
app = Flask(__name__)
# ページ配信
@app.get("/")
def index():
"""
templates/index.html を返す
Flaskでは templates/ がHTMLの場所として扱われる
"""
return render_template("index.html")
# API
@app.get("/api/health")
def health():
"""
動作確認用API
"""
return jsonify(ok=True, message="hello from Flask")
@app.post("/api/echo")
def echo():
"""
フロントから送られたJSONをそのまま返すAPI
"""
data = request.get_json(silent=True) or {}
print("Received data:", data, flush=True)
return jsonify(ok=True, you_sent=data)
# 直接実行時のみ起動
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)