diff --git a/conf/nginx.certbot.conf b/conf/nginx.certbot.conf index 4372827..c712ff4 100644 --- a/conf/nginx.certbot.conf +++ b/conf/nginx.certbot.conf @@ -5,10 +5,7 @@ proxy_cache_path /var/cache/nginx/corelle_api server { - listen 443 ssl proxy_protocol; - server_name rotate.macrostrat.org; - ssl_certificate /etc/letsencrypt/live/rotate.macrostrat.org/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/rotate.macrostrat.org/privkey.pem; + listen 80; client_max_body_size 20M; proxy_cache_background_update on; diff --git a/conf/nginx.conf b/conf/nginx.conf index 796604f..ab3d878 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -25,6 +25,7 @@ http { proxy_cache corelle_api; proxy_pass http://backend; proxy_http_version 1.1; + default_type application/json; } location / { diff --git a/corelle/api.py b/corelle/api.py index 2abe889..33ac51b 100644 --- a/corelle/api.py +++ b/corelle/api.py @@ -13,6 +13,7 @@ get_plate_rotations, get_rotation_series, rotate_point, + rotate_point_for_api, ) app = Flask(__name__) @@ -192,10 +193,11 @@ def get(self): for p in points: [lon, lat] = p.split(",") pt = [float(lon), float(lat)] - res = rotate_point(pt, args["model"], args["time"]) + res = rotate_point_for_api(pt, args["model"], args["time"]) if res is not None: - res = dict(type="Feature", geometry=dict(type="Point", coordinates=res)) - out_points.append(res) + out_points.append(dict(type="Feature", + geometry=dict(type="Point", coordinates=res['coordinates']), + properties=dict(plate_id=res['plate_id']))) else: if args["include_failures"]: out_points.append(None) diff --git a/corelle/rotate/engine.py b/corelle/rotate/engine.py index 7326ad2..9ec3202 100644 --- a/corelle/rotate/engine.py +++ b/corelle/rotate/engine.py @@ -156,11 +156,30 @@ def rotate_point(point, model, time): if plate_id is None: return None q = get_rotation(model, plate_id, time) + if q is None: + return None v0 = sph2cart(*point) v1 = Q.rotate_vectors(q, v0) return cart2sph(v1) +def rotate_point_for_api(point, model, time): + if time == 0: + return point + sql = get_sql("plate-for-point") + plate_id = conn.execute( + sql, lon=point[0], lat=point[1], model_name=model, time=time + ).scalar() + if plate_id is None: + return None + q = get_rotation(model, plate_id, time) + if q is None: + return None + v0 = sph2cart(*point) + v1 = Q.rotate_vectors(q, v0) + return dict(coordinates=cart2sph(v1), plate_id=plate_id) + + __tstep_rotation_pairs = get_sql("rotation-pairs-for-time") __model_rotation_pairs = get_sql("rotation-pairs-for-model") __active_plates_sql = get_sql("active-plates-at-time") diff --git a/docker-compose.production.yaml b/docker-compose.production.yaml index 2ebcd29..942ff48 100644 --- a/docker-compose.production.yaml +++ b/docker-compose.production.yaml @@ -2,19 +2,12 @@ version: "3" services: gateway: restart: unless-stopped - image: jonasal/nginx-certbot depends_on: - api ports: - "${CORELLE_HTTP_PORT}:80" - - "${CORELLE_HTTPS_PORT}:443" - environment: - - CERTBOT_EMAIL - # Substitute in value for SPARROW_DOMAIN - # - CORELLE_DOMAIN volumes: - # Swap out nginx conf for a certbot version - - ./conf/nginx.certbot.conf:/etc/nginx/user_conf.d/site.conf:ro + - ./conf/nginx.conf:/etc/nginx/nginx.conf:ro api: restart: unless-stopped database: diff --git a/requirements.txt b/requirements.txt index 77c4242..a3d0238 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,5 @@ Flask Flask-Restful simplejson fiona +SQLAlchemy==1.4 +werkzeug==2.0.0