diff --git a/example-nginx.conf b/example-nginx.conf new file mode 100644 index 0000000..e7cd14f --- /dev/null +++ b/example-nginx.conf @@ -0,0 +1,16 @@ +server { + listen 80; + server_name www.example.com; + + location / { + root /path/to/aliexpress-price-tracker/web; + index app.html; + } + location ~ ^/app/(.*)$ { + proxy_pass http://127.0.0.1:8080/$1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} diff --git a/requirements.txt b/requirements.txt index dcfdbc7..690bd24 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ Flask +flask-cors gunicorn psycopg2-binary requests diff --git a/src/app.py b/src/app.py index 2fa3d73..ab229d1 100644 --- a/src/app.py +++ b/src/app.py @@ -1,9 +1,11 @@ from flask import Flask, request, jsonify +from flask_cors import CORS import requests, re, json, os, yaml from db import * from aliexpress import * app = Flask(__name__) +CORS(app) def get_conf(): '''return settings in settings.yaml file''' diff --git a/web/app.js b/web/app.js index 1a863eb..4650fd6 100644 --- a/web/app.js +++ b/web/app.js @@ -13,7 +13,6 @@ const width = window.innerWidth - margin.right - margin.left -10; // url const currentUrl = window.location.href; -console.log(currentUrl); // reload page when window is resized @@ -22,7 +21,7 @@ window.onresize = function(){ location.reload(); } async function fetch_history() { try { - const response = await fetch(`${currentUrl}/datahistory`); + const response = await fetch(`${currentUrl}app/datahistory`); const rawData = await response.json(); // SELECT uuid, quantity, discount_percentage, price, currency, h_timestamp let historyData = rawData.map(d => ({ @@ -41,7 +40,7 @@ async function fetch_history() { async function fetch_item() { try { // SELECT uuid, itemid, skuid, choice, attributes, image - const response = await fetch(`${currentUrl}/dataitem`); + const response = await fetch(`${currentUrl}app/dataitem`); const rawData = await response.json(); const items = rawData.reduce((item, row) => { const uuid = row[0];