Implement the rest api for get requests

This commit is contained in:
Kosh 2023-10-10 22:58:44 +05:30
parent 2890316405
commit ab65b8f66f

20
backend/rest_api.py Normal file
View File

@ -0,0 +1,20 @@
from flask import Flask, send_file, abort, Response
from os import path
app: Flask = Flask(__name__)
@app.get("/")
@app.get("/<url_path>")
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)