Spaces:
Sleeping
Sleeping
Update proxy/proxy_server.py
Browse files- proxy/proxy_server.py +35 -8
proxy/proxy_server.py
CHANGED
|
@@ -16,7 +16,7 @@ def index():
|
|
| 16 |
|
| 17 |
|
| 18 |
# ---------------------------------------------------------
|
| 19 |
-
# 2. Reverse proxy to ConlluEditor (
|
| 20 |
# ---------------------------------------------------------
|
| 21 |
@app.route("/editor/", defaults={"path": ""}, methods=["GET", "POST"])
|
| 22 |
@app.route("/editor/<path:path>", methods=["GET", "POST"])
|
|
@@ -42,8 +42,40 @@ def proxy_editor(path):
|
|
| 42 |
)
|
| 43 |
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
# ---------------------------------------------------------
|
| 46 |
-
#
|
| 47 |
# ---------------------------------------------------------
|
| 48 |
@app.route("/api/<path:path>", methods=["GET", "POST"])
|
| 49 |
def proxy_api(path):
|
|
@@ -53,7 +85,6 @@ def proxy_api(path):
|
|
| 53 |
|
| 54 |
if request.method == "GET":
|
| 55 |
r = requests.get(url, headers=_filtered_headers(), stream=True)
|
| 56 |
-
|
| 57 |
else:
|
| 58 |
# Forward raw body + content-type so Flask can parse multipart uploads
|
| 59 |
r = requests.post(
|
|
@@ -69,13 +100,9 @@ def proxy_api(path):
|
|
| 69 |
headers=_proxied_response_headers(r)
|
| 70 |
)
|
| 71 |
|
| 72 |
-
@app.route("/editor", methods=["GET", "POST"])
|
| 73 |
-
def proxy_editor_noslash():
|
| 74 |
-
return proxy_editor("")
|
| 75 |
-
|
| 76 |
|
| 77 |
# ---------------------------------------------------------
|
| 78 |
-
#
|
| 79 |
# ---------------------------------------------------------
|
| 80 |
@app.route("/<path:path>", methods=["GET", "POST"])
|
| 81 |
def proxy_static(path):
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
# ---------------------------------------------------------
|
| 19 |
+
# 2. Reverse proxy to ConlluEditor (UI + static)
|
| 20 |
# ---------------------------------------------------------
|
| 21 |
@app.route("/editor/", defaults={"path": ""}, methods=["GET", "POST"])
|
| 22 |
@app.route("/editor/<path:path>", methods=["GET", "POST"])
|
|
|
|
| 42 |
)
|
| 43 |
|
| 44 |
|
| 45 |
+
# Handle /editor (no slash)
|
| 46 |
+
@app.route("/editor", methods=["GET", "POST"])
|
| 47 |
+
def proxy_editor_noslash():
|
| 48 |
+
return proxy_editor("")
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
# ---------------------------------------------------------
|
| 52 |
+
# 3. Reverse proxy for ConlluEditor internal API (/edit/*)
|
| 53 |
+
# ---------------------------------------------------------
|
| 54 |
+
@app.route("/edit/<path:path>", methods=["GET", "POST"])
|
| 55 |
+
def proxy_editor_api(path):
|
| 56 |
+
url = f"{EDITOR_BASE}/edit/{path}"
|
| 57 |
+
if request.query_string:
|
| 58 |
+
url += "?" + request.query_string.decode()
|
| 59 |
+
|
| 60 |
+
if request.method == "GET":
|
| 61 |
+
r = requests.get(url, headers=_filtered_headers(), stream=True)
|
| 62 |
+
else:
|
| 63 |
+
r = requests.post(
|
| 64 |
+
url,
|
| 65 |
+
data=request.get_data(),
|
| 66 |
+
headers={"Content-Type": request.headers.get("Content-Type")},
|
| 67 |
+
stream=True
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
return Response(
|
| 71 |
+
r.iter_content(chunk_size=8192),
|
| 72 |
+
status=r.status_code,
|
| 73 |
+
headers=_proxied_response_headers(r)
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
# ---------------------------------------------------------
|
| 78 |
+
# 4. Reverse proxy to Upload API (/api/*)
|
| 79 |
# ---------------------------------------------------------
|
| 80 |
@app.route("/api/<path:path>", methods=["GET", "POST"])
|
| 81 |
def proxy_api(path):
|
|
|
|
| 85 |
|
| 86 |
if request.method == "GET":
|
| 87 |
r = requests.get(url, headers=_filtered_headers(), stream=True)
|
|
|
|
| 88 |
else:
|
| 89 |
# Forward raw body + content-type so Flask can parse multipart uploads
|
| 90 |
r = requests.post(
|
|
|
|
| 100 |
headers=_proxied_response_headers(r)
|
| 101 |
)
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
# ---------------------------------------------------------
|
| 105 |
+
# 5. Catch‑all: static assets for ConlluEditor
|
| 106 |
# ---------------------------------------------------------
|
| 107 |
@app.route("/<path:path>", methods=["GET", "POST"])
|
| 108 |
def proxy_static(path):
|