From ca958fdd272e5eae5a27404b529050455e62dca7 Mon Sep 17 00:00:00 2001 From: Rolf Niepraschk <Rolf.Niepraschk@ptb.de> Date: Tue, 10 Nov 2020 15:20:30 +0100 Subject: [PATCH] all the urls to send file content --- server.py | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/server.py b/server.py index 07e1841..1cd9169 100644 --- a/server.py +++ b/server.py @@ -10,11 +10,44 @@ app = Flask(__name__) COUCHDB_PROTO = 'http' COUCHDB_HOST = '127.0.0.1' COUCHDB_PORT = '5984' +DB = 'vl_db' app = Flask(__name__, static_url_path='') app.url_map.strict_slashes = False CORS(app) +## =================== URLs to the Web Apps ====================== + +@app.route('/<fn>', methods=['GET']) +def html(fn): + app.logger.debug('hit html folder: ' + fn) + return send_from_directory('./data/web-apps', fn) + +@app.route('/js/<path:fn>', methods=['GET']) +def js(fn): + app.logger.debug('hit js folder: ' + fn) + return send_from_directory('data/web-apps/js', fn) + +@app.route('/css/<fn>', methods=['GET']) +def css(fn): + app.logger.debug('hit css folder: ' + fn) + return send_from_directory('data/web-apps/css', fn) + +@app.route('/img/<fn>', methods=['GET']) +def img(fn): + app.logger.debug('hit img folder: ' + fn) + return send_from_directory('data/web-apps/img', fn) + +@app.route('/lib/<path:fn>', methods=['GET']) +def lib(fn): + app.logger.debug('hit lib folder: ' + fn) + return send_from_directory('data/lib', fn) + +## ------------------------------------ +## CouchDB Proxy +## from: http://host/5984/foo/bar +## to: http://127.0.0.1:5984/foo/bar +## ------------------------------------ def couchdb_proxy_1(path): new_url = '{}://{}:{}/{}'.format(COUCHDB_PROTO, COUCHDB_HOST, \ COUCHDB_PORT, path) @@ -25,16 +58,14 @@ def couchdb_proxy_1(path): headers={key: value for (key, value) in request.headers if key != 'Host'}, data=request.get_data(), cookies=request.cookies, - allow_redirects=False) - headers = [(name, value) for (name, value) in resp.raw.headers.items()] + allow_redirects=False) + excluded_headers = ['content-encoding', 'content-length', \ + 'transfer-encoding', 'connection'] + headers = [(name, value) for (name, value) in resp.raw.headers.items() + if name.lower() not in excluded_headers] response = Response(resp.content, resp.status_code, headers) return response -## ------------------------------------ -## CouchDB Proxy -## from: http://host/5984/foo/bar -## to: http://127.0.0.1:5984/foo/bar -## ------------------------------------ @app.route('/{}/'.format(COUCHDB_PORT), \ methods=['GET','PUT','POST','HEAD','DELETE','OPTIONS']) @app.route('/{}/<path:path>'.format(COUCHDB_PORT), -- GitLab