-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
32 lines (24 loc) · 857 Bytes
/
main.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
import json
from flask import Flask, request, jsonify
app = Flask(__name__)
def read_config():
with open('data.json') as json_file:
return json.load(json_file)
def write_config(data):
with open('data.json', 'w') as outfile:
json.dump(data, outfile)
@app.route('/config', methods=['GET', 'POST'])
def get_config():
if request.method == 'POST':
write_config(request.get_json())
response = jsonify(read_config())
return response
else:
response = jsonify(read_config())
return response
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', '*')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
return response