From ab65b8f66f0dd115e7f92981a939b2ae2b80720a Mon Sep 17 00:00:00 2001 From: Kosh Date: Tue, 10 Oct 2023 22:58:44 +0530 Subject: [PATCH] Implement the rest api for get requests --- backend/rest_api.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 backend/rest_api.py diff --git a/backend/rest_api.py b/backend/rest_api.py new file mode 100644 index 0000000..ff0919d --- /dev/null +++ b/backend/rest_api.py @@ -0,0 +1,20 @@ +from flask import Flask, send_file, abort, Response +from os import path + + +app: Flask = Flask(__name__) + +@app.get("/") +@app.get("/") +def handle_get(url_path: str = "index.html") -> Response: + """ + Handle all get requests that are made. + """ + requested_file_path: str = \ + path.abspath(path.join(path.curdir, "..", "frontend", url_path)) + response: Response = send_file(requested_file_path) + response.status = 200 + if path.isfile(requested_file_path): + print('a') + return send_file(requested_file_path) + abort(404)