Skip to content
Snippets Groups Projects
Commit e12a5904 authored by Rolf Niepraschk's avatar Rolf Niepraschk
Browse files

...

parent b9ea47c2
No related branches found
No related tags found
No related merge requests found
...@@ -6,10 +6,7 @@ import sys, requests ...@@ -6,10 +6,7 @@ import sys, requests
app = Flask(__name__) app = Flask(__name__)
VERSION = '1.0.0' VERSION = '1.1.0'
COUCHDB_PROTO = 'http'
COUCHDB_PORT = '5984'
FLASK_RUN_PORT = sys.argv[1] FLASK_RUN_PORT = sys.argv[1]
DATA_PATH = sys.argv[2] DATA_PATH = sys.argv[2]
...@@ -38,24 +35,27 @@ def x(p1, p2=''): ...@@ -38,24 +35,27 @@ def x(p1, p2=''):
The following works like a proxy server: The following works like a proxy server:
A flask server URL of the form A flask server URL of the form
"http://127.0.0.1:8081/5984/vl_db/000_SERVERS" "http://127.0.0.1:8081/xxxx/vl_db/000_SERVERS"
will be forwarded to the real CouchDB URL will be forwarded to the real CouchDB URL
"http://127.0.0.1:5984/vl_db/000_SERVERS" "http://127.0.0.1:xxxx/vl_db/000_SERVERS"
The part 'xxxx' can be any integer as a future port address for couchdb.
see: see:
https://stackoverflow.com/questions/6656363/proxying-to-another-web-service-with-flask https://stackoverflow.com/questions/6656363/proxying-to-another-web-service-with-flask
''' '''
@app.route('/{}/'.format(COUCHDB_PORT), \ @app.route('/<int:real_port>/', \
methods=['GET','PUT','POST','HEAD','DELETE','OPTIONS']) methods=['GET','PUT','POST','HEAD','DELETE','OPTIONS'])
@app.route('/{}/<path:p>'.format(COUCHDB_PORT), @app.route('/<int:real_port>/<path:p>',
methods=['GET','PUT','POST','HEAD','DELETE','OPTIONS']) methods=['GET','PUT','POST','HEAD','DELETE','OPTIONS'])
def couchdb_proxy(p=''): def couchdb_proxy(real_port, p=''):
q = request.query_string.decode(); q = request.query_string.decode();
path = p path = p
if q: if q:
path = p + '?' + q path = p + '?' + q
host = urlparse(request.base_url).hostname host = urlparse(request.base_url).hostname
new_url = '{}://{}:{}/{}'.format(COUCHDB_PROTO, host, COUCHDB_PORT, path) scheme = urlparse(request.base_url).scheme
new_url = '{}://{}:{}/{}'.format(scheme, host, real_port, path)
app.logger.debug('[old couchdb url] ' + request.url) app.logger.debug('[old couchdb url] ' + request.url)
app.logger.debug('[new couchdb url] ' + new_url) app.logger.debug('[new couchdb url] ' + new_url)
resp = requests.request( resp = requests.request(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment