restructured how data subdomain serves air.json to main domain by mounting the dyn folder directly into the main docker container, by that avoiding any CORS complications.

This commit is contained in:
simon 2021-02-22 10:33:24 +07:00
parent 56199766ee
commit 12f3a52304
10 changed files with 15 additions and 11 deletions

View File

@ -1 +1,2 @@
__pycache__
__pycache__
/dyn/*

View File

@ -4,6 +4,8 @@ FROM python
# Set the working directory to /app
WORKDIR /app
VOLUME /app/dyn
# Copy the current directory contents into the container at /app
ADD . /app

View File

@ -1,7 +1,6 @@
import configparser
import json
from flask_cors import CORS
from flask import request
from flask_httpauth import HTTPBasicAuth
from apscheduler.schedulers.background import BackgroundScheduler
@ -12,7 +11,6 @@ from app import aqi_parser
from app import weather
from app import db_insert
cors = CORS(app, resources={r"/": {"origins": "*"}})
auth = HTTPBasicAuth()

View File

@ -1 +0,0 @@
{"uptime": 1476, "temperature": 28.46, "pressure": 975.0873, "humidity": 40.52051, "pm25": 11, "pm10": 64.4, "aqi_value": 45.0, "aqi_category": "Good", "timestamp": "2021-02-14 14:27:06", "epoch_time": 1613287626}

View File

@ -1 +0,0 @@
{"weather_name": "Clouds", "weather_icon": "02d", "wind_speed": 2.06, "wind_direction": 180, "timestamp": "2021-02-16 14:32:52", "epoch_time": 1613460772}

View File

@ -1,6 +1,5 @@
apscheduler
Flask
flask-cors
Flask-HTTPAuth
numpy
psycopg2-binary

View File

@ -1,15 +1,14 @@
#!/bin/bash
# upload project to vps2
# get last dyn
wget data.lpb-air.com --output-document=backend/flask/dyn/air.json
rsync --progress -a docker-compose.yml vps2:docker/
rsync --progress -a env vps2:docker/
rsync --progress -a --delete-after \
--exclude dyn --exclude config.sample --exclude __pychache__ \
backend vps2:docker/
rsync --progress -a --delete-after frontend vps2:docker/
rsync --progress -a --delete-after \
--exclude dyn \
frontend vps2:docker/
##
exit 0

View File

@ -37,6 +37,8 @@ services:
build: ./backend/flask
container_name: flask
restart: always
volumes:
- ./volume/flask/dyn:/app/dyn
environment:
- APP_NAME=FlaskBackend
- TZ=Asia/Bangkok
@ -79,6 +81,7 @@ services:
- "80"
volumes:
- ./frontend/nginx:/air:rw
- ./volume/flask/dyn:/dyn:ro
- ./frontend/nginx.conf:/etc/nginx/conf.d/default.conf
environment:
- VIRTUAL_HOST=www.lpb-air.com,lpb-air.com

View File

@ -6,6 +6,10 @@ server {
access_log /var/log/nginx/access.log;
root /air;
location /dyn/ {
alias /dyn/;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;

View File

@ -58,7 +58,7 @@ function startInterval() {
function refreshAqiValues() {
var req = new XMLHttpRequest();
req.responseType = 'json';
req.open('GET', 'https://data.lpb-air.com', true);
req.open('GET', '/dyn/air.json', true);
req.setRequestHeader('cache-control', 'no-cache');
req.onload = function() {
var responseAqi = req.response;