From e12a5904176a1e755c47653d40a96d8c4f14ca75 Mon Sep 17 00:00:00 2001
From: Rolf Niepraschk <Rolf.Niepraschk@ptb.de>
Date: Thu, 12 Nov 2020 14:34:15 +0100
Subject: [PATCH] ...

---
 server.py | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/server.py b/server.py
index 75ba294..cddf73a 100644
--- a/server.py
+++ b/server.py
@@ -6,10 +6,7 @@ import sys, requests
 
 app = Flask(__name__)
 
-VERSION = '1.0.0'
-
-COUCHDB_PROTO = 'http' 
-COUCHDB_PORT = '5984'
+VERSION = '1.1.0'
 
 FLASK_RUN_PORT = sys.argv[1]
 DATA_PATH = sys.argv[2]
@@ -38,24 +35,27 @@ def x(p1, p2=''):
 The following works like a proxy server:
 
 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 
-  "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:
 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']) 
-@app.route('/{}/<path:p>'.format(COUCHDB_PORT),
+@app.route('/<int:real_port>/<path:p>',
   methods=['GET','PUT','POST','HEAD','DELETE','OPTIONS']) 
-def couchdb_proxy(p=''):
+def couchdb_proxy(real_port, p=''):
     q = request.query_string.decode();
     path = p
     if q:
         path = p + '?' + q
     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('[new couchdb url] ' + new_url)
     resp = requests.request(
-- 
GitLab