server static files with Flask
This commit is contained in:
parent
1151c3e9a2
commit
49574602ed
@ -9,6 +9,7 @@ RUN pip3 install -r /requirements.txt
|
||||
|
||||
|
||||
COPY ./src /app
|
||||
COPY ./web /web
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
@ -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;
|
||||
|
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")
|
||||
|
@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<!-- <link href='https://overpass-30e2.kxcdn.com/overpass.css' rel='stylesheet'> -->
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||
<title>Aliexpress price tracker</title>
|
||||
</head>
|
||||
<body>
|
||||
@ -45,7 +45,7 @@
|
||||
<div class="content" id="graphs"></div>
|
||||
|
||||
<!-- Load scripts-->
|
||||
<script src="fetch.js"></script>
|
||||
<script src="rendergraphs.js"></script>
|
||||
<script src="app.js"></script>
|
||||
<script src="{{ url_for('static', filename='fetch.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='rendergraphs.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='app.js') }}"></script>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user