minor improvements
This commit is contained in:
parent
0c07d7ea93
commit
2538e54764
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@
|
||||||
/shelf/
|
/shelf/
|
||||||
/workspace.xml
|
/workspace.xml
|
||||||
.env
|
.env
|
||||||
|
.pyc
|
||||||
|
|
4
main.py
4
main.py
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
from flask_cors import CORS
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
from routes import register_route
|
from routes import register_route
|
||||||
|
|
||||||
|
@ -13,5 +14,8 @@ db.init_app(app)
|
||||||
|
|
||||||
register_route(app, db)
|
register_route(app, db)
|
||||||
|
|
||||||
|
CORS(app, resources={r"/find_agents": {"origins": os.getenv("ORIGINS")}})
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
|
13
routes.py
13
routes.py
|
@ -1,5 +1,5 @@
|
||||||
import os
|
import os
|
||||||
from flask import jsonify, request
|
from flask import jsonify, request, make_response
|
||||||
from sqlalchemy import inspect, func, text
|
from sqlalchemy import inspect, func, text
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
from geoalchemy2 import Geometry
|
from geoalchemy2 import Geometry
|
||||||
|
@ -16,11 +16,18 @@ def register_route(app,db):
|
||||||
tables = inspector.get_table_names()
|
tables = inspector.get_table_names()
|
||||||
return jsonify(tables)
|
return jsonify(tables)
|
||||||
|
|
||||||
@app.route('/find_points/', methods=['POST'])
|
@app.route('/find_agents', methods=['POST','OPTIONS'])
|
||||||
def find_points():
|
def find_points():
|
||||||
|
if request.method == 'OPTIONS':
|
||||||
|
response = make_response()
|
||||||
|
response.headers.add("Access-Control-Allow-Origin", "http://localhost:4000")
|
||||||
|
response.headers.add('Access-Control-Allow-Headers', 'Content-Type')
|
||||||
|
response.headers.add('Access-Control-Allow-Methods', 'POST, OPTIONS')
|
||||||
|
return response
|
||||||
|
elif request.method == 'POST':
|
||||||
data = request.json
|
data = request.json
|
||||||
coordinates = data.get('coordinates', [])
|
coordinates = data.get('coordinates', [])
|
||||||
polygon_wkt = 'POLYGON(({}))'.format(', '.join(f'{lat} {lng}' for lat, lng in coordinates))
|
polygon_wkt = 'POLYGON(({}))'.format(', '.join(f'{lng} {lat}' for lat, lng in coordinates))
|
||||||
|
|
||||||
# Construct the query string
|
# Construct the query string
|
||||||
query = f"""
|
query = f"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user