server static files with Flask
This commit is contained in:
26
src/app.py
26
src/app.py
@ -1,26 +1,30 @@
|
||||
from flask import Flask, request, jsonify
|
||||
from flask import Flask, request, jsonify, render_template
|
||||
from flask_cors import CORS
|
||||
import requests, re, json, os, yaml
|
||||
from db import *
|
||||
from aliexpress import *
|
||||
|
||||
app = Flask(__name__)
|
||||
app = Flask(__name__, template_folder='/web', static_folder='/web')
|
||||
CORS(app)
|
||||
|
||||
@app.route('/init', methods = ['GET'])
|
||||
@app.route("/")
|
||||
def serve_index():
|
||||
return render_template('app.html')
|
||||
|
||||
@app.route('/app/init', methods = ['GET'])
|
||||
def init_db():
|
||||
status = check_schema()
|
||||
if not status:
|
||||
initialize()
|
||||
return str(status)
|
||||
|
||||
@app.route('/update', methods = ['GET'])
|
||||
@app.route('/app/update', methods = ['GET'])
|
||||
def update_hist():
|
||||
print("update")
|
||||
update_items()
|
||||
return 'items updated'
|
||||
|
||||
@app.route('/add', methods=['POST'])
|
||||
@app.route('/app/add', methods=['POST'])
|
||||
def add_item():
|
||||
print("adding item")
|
||||
|
||||
@ -45,7 +49,7 @@ def add_item():
|
||||
# item not valid or can't be parsed
|
||||
return jsonify({'status': 1}), 400
|
||||
|
||||
@app.route('/delete', methods=['POST'])
|
||||
@app.route('/app/delete', methods=['POST'])
|
||||
def del_item():
|
||||
print("deleting item")
|
||||
data = request.get_json()
|
||||
@ -53,14 +57,14 @@ def del_item():
|
||||
delete_item(uuid)
|
||||
return jsonify({'deleted': uuid}), 200
|
||||
|
||||
@app.route('/show', methods=['POST'])
|
||||
@app.route('/app/show', methods=['POST'])
|
||||
def toggle_item_show():
|
||||
data = request.get_json()
|
||||
uuid = data.get('uuid')
|
||||
toggle_show(uuid)
|
||||
return jsonify({'toggled show/hide ': uuid}), 200
|
||||
|
||||
@app.route('/create-list', methods=['POST'])
|
||||
@app.route('/app/create-list', methods=['POST'])
|
||||
def createList():
|
||||
data = request.get_json()
|
||||
name = data.get('name')
|
||||
@ -68,7 +72,7 @@ def createList():
|
||||
create_list(name, description)
|
||||
return jsonify({'created list ': name}), 200
|
||||
|
||||
@app.route('/add-to-list', methods=['POST'])
|
||||
@app.route('/app/add-to-list', methods=['POST'])
|
||||
def addToList():
|
||||
date = request.get_json()
|
||||
list_uuid = data.get('list_uuid')
|
||||
@ -76,13 +80,13 @@ def addToList():
|
||||
add_to_list(list_uuid, item_uuid)
|
||||
return jsonify({'list': list_uuid, 'item': item_uuid}), 200
|
||||
|
||||
@app.route('/datahistory',methods = ['GET'])
|
||||
@app.route('/app/datahistory',methods = ['GET'])
|
||||
def data_history_request():
|
||||
if request.method == 'GET':
|
||||
print("fetching data history")
|
||||
return jsonify(get_history())
|
||||
|
||||
@app.route('/dataitem',methods = ['GET'])
|
||||
@app.route('/app/dataitem',methods = ['GET'])
|
||||
def data_item_request():
|
||||
if request.method == 'GET':
|
||||
print("fetching data item")
|
||||
|
Reference in New Issue
Block a user