-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
32 lines (27 loc) · 971 Bytes
/
app.py
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
try:
from flask import Flask, jsonify, request
except ImportError:
print("flask not installed")
from flask_cors import CORS
import os
import json
app = Flask(__name__)
# Enable CORS for all domains on all routes
CORS(app)
config_file_path = '/home/pi/bcMeter_config.json'
@app.route('/load-config', methods=['GET'])
def load_config():
if os.path.exists(config_file_path):
with open(config_file_path, 'r') as config_file:
config = json.load(config_file)
return jsonify(config), 200
else:
return jsonify({"error": "Configuration file not found."}), 404
@app.route('/save-config', methods=['POST'])
def save_config():
config_data = request.json
with open(config_file_path, 'w') as config_file:
json.dump(config_data, config_file, indent=4)
return jsonify({"message": "Configuration saved successfully."}), 200
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=False)