Skip to content

Commit b59bf45

Browse files
committed
Remove unnecessary parsing code on wildcard path for slight performance improvement
1 parent 7b2590a commit b59bf45

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

flaskProxyWithAuth.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def index():
6666
if user:
6767
#return jsonify({"message": "You are authenticated!", "user": user}), 200
6868
target_url = f"http://localhost:{internal_app_port}/"
69-
7069
return internal_request_handler(request, target_url)
7170
else:
7271
redirect_uri = url_for("oauth2", _external=True)
@@ -79,15 +78,11 @@ def index():
7978
# ''')
8079

8180
# Custom route to handle arbitrary path sequences
82-
@app.route("/<path:arbitrary_path>", methods=["GET", "POST", "PUT", "DELETE"])
83-
def flask_internal_proxy(arbitrary_path):
81+
@app.route("/<path:some_path>", methods=["GET", "POST", "PUT", "DELETE"])
82+
def flask_internal_proxy(some_path):
8483
user = session.get("user")
8584
if user:
86-
# Convert the arbitrary path string to a list
87-
path_elements = arbitrary_path.split("/")
88-
# Build the target_url dynamically
89-
target_url = f"http://localhost:{internal_app_port}/" + "/".join(path_elements)
90-
85+
target_url = f"http://localhost:{internal_app_port}/{some_path}"
9186
return internal_request_handler(request, target_url)
9287
else:
9388
redirect_uri = url_for("oauth2", _external=True)

0 commit comments

Comments
 (0)