Spaces:
Sleeping
Sleeping
| from flask import Flask, render_template, jsonify, request | |
| import os | |
| import json | |
| app = Flask(__name__) | |
| # Change Jinja2 delimiters to avoid conflict with Vue.js | |
| app.jinja_env.variable_start_string = '[[' | |
| app.jinja_env.variable_end_string = ']]' | |
| DATA_FILE = os.path.join('data', 'roadmap.json') | |
| def ensure_data_dir(): | |
| if not os.path.exists('data'): | |
| os.makedirs('data') | |
| def index(): | |
| return render_template('index.html') | |
| def health(): | |
| return jsonify({"status": "healthy"}) | |
| def get_data(): | |
| if os.path.exists(DATA_FILE): | |
| try: | |
| with open(DATA_FILE, 'r', encoding='utf-8') as f: | |
| data = json.load(f) | |
| return jsonify(data) | |
| except Exception as e: | |
| return jsonify({"error": str(e)}), 500 | |
| return jsonify(None) | |
| def save_data(): | |
| ensure_data_dir() | |
| try: | |
| data = request.json | |
| with open(DATA_FILE, 'w', encoding='utf-8') as f: | |
| json.dump(data, f, ensure_ascii=False, indent=2) | |
| return jsonify({"status": "success"}) | |
| except Exception as e: | |
| return jsonify({"error": str(e)}), 500 | |
| if __name__ == '__main__': | |
| port = int(os.environ.get('PORT', 7860)) | |
| app.run(host='0.0.0.0', port=port) | |