services
This commit is contained in:
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/python3
|
||||
from flask import Flask, request, redirect
|
||||
import requests as r
|
||||
app = Flask(__name__)
|
||||
proxy_node_port = 5000
|
||||
static_node_port = 5001
|
||||
logic_node_port = 5003
|
||||
content_node_port = 5004
|
||||
static_node = "static:" + str(static_node_port)
|
||||
logic_node = "logic:" + str(logic_node_port)
|
||||
content_node = "content:" + str(content_node_port)
|
||||
|
||||
|
||||
@app.route('/', defaults={'path': 'index.html'})
|
||||
@app.route('/<path:path>', methods=["GET", "POST"])
|
||||
def catch_all(path: str):
|
||||
print(path)
|
||||
ext = path.split('.')[-1]
|
||||
if ext == "html":
|
||||
resp = r.get(f"http://{content_node}/{path}?{request.full_path.split('?')[1]}", headers=request.headers)
|
||||
return resp.content, resp.status_code, resp.headers.items()
|
||||
if ext in ["css", "png", "jpg", "ico", "js", "otf", "eot", "svg", "ttf", "woff", "woff2"]:
|
||||
resp = r.get(f"http://{static_node}/{path}", stream=True)
|
||||
headers = [("Cache-Control", "max-age=36000;"), ("Content-Type", resp.headers["Content-Type"])]
|
||||
return resp.content, resp.status_code, headers
|
||||
if path.startswith("api/"):
|
||||
passcall = getattr(r, request.method.lower())
|
||||
resp = passcall(f"http://{logic_node}/{path[4:]}", json=request.get_json(), headers=request.headers)
|
||||
return resp.content, resp.status_code, resp.headers.items()
|
||||
return redirect("/", code=302)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host="0.0.0.0", port=proxy_node_port)
|
||||
Reference in New Issue
Block a user