diff --git a/Dockerfile b/Dockerfile index fef5efd..ff8465e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ RUN pip3 install -r /requirements.txt COPY ./src /app +COPY ./web /web WORKDIR /app diff --git a/example-nginx.conf b/example-nginx.conf index e7cd14f..d6a39fd 100644 --- a/example-nginx.conf +++ b/example-nginx.conf @@ -1,13 +1,9 @@ server { listen 80; - server_name www.example.com; + server_name test.localhost; location / { - root /path/to/aliexpress-price-tracker/web; - index app.html; - } - location ~ ^/app/(.*)$ { - proxy_pass http://127.0.0.1:8080/$1; + proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; diff --git a/src/app.py b/src/app.py index 046d8eb..76c2d9a 100644 --- a/src/app.py +++ b/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") diff --git a/web/app.html b/web/app.html index b2b79d4..440ec3e 100644 --- a/web/app.html +++ b/web/app.html @@ -4,7 +4,7 @@ - + Aliexpress price tracker @@ -45,7 +45,7 @@
- - - + + +