-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
27 lines (21 loc) · 886 Bytes
/
Copy pathapp.py
File metadata and controls
27 lines (21 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from flask import Flask, render_template, request, jsonify
import requests
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def index():
algorithm = request.args.get("algorithm", "round_robin")
if request.method == "POST":
# Send a request to the load balancer
try:
response = requests.get(
f"http://load_balancer:5004/route?algorithm={algorithm}")
if response.status_code == 200:
data = response.json()
return jsonify(data)
else:
return jsonify({"error": "Backend server is down"}), 500
except requests.RequestException as e:
return jsonify({"error": "Failed to connect to load balancer", "details": str(e)}), 503
return render_template("index.html")
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5005)