From ea8721659ccfc6f1376c418c4f19c17664c82360 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Tue, 18 May 2021 23:12:00 +0200 Subject: [PATCH] First attempt at using blueprints --- Makefile | 4 ++-- app/__main__.py | 8 ++++++-- app/api/__init__.py | 8 ++++++++ app/api/search.py | 11 +++++++++++ .mocharc.yml => web/.mocharc.yml | 0 5 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 app/api/__init__.py create mode 100644 app/api/search.py rename .mocharc.yml => web/.mocharc.yml (100%) diff --git a/Makefile b/Makefile index 6b6e2c5..dcaf859 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ PYTHON := python3 # This can't contain spaces (I think) VENV := .venv # Minimum % coverage for tests to succeed -MIN_COV := 0 +MIN_COV := 50 # Directory name for the frontend WEB_DIR := web @@ -55,7 +55,7 @@ test: venv ## Starting the server ### Run the Quart server run: venv - @ '$(VENV)'/bin/python app + @ QUART_ENV=development '$(VENV)'/bin/python app .PHONY: run diff --git a/app/__main__.py b/app/__main__.py index 3848299..f2f91da 100644 --- a/app/__main__.py +++ b/app/__main__.py @@ -1,7 +1,9 @@ -"""Main entrypoint for the program.""" +"""Entrypoint for the program.""" from quart import Quart +from app.api import blueprint app = Quart("jos", static_folder="web/dist", static_url_path="/") +app.register_blueprint(blueprint) @app.route("/", methods=["GET"], defaults={"path": ""}) @@ -11,4 +13,6 @@ async def frontend(path): return await app.send_static_file("index.html") -app.run(host="0.0.0.0") +if __name__ == "__main__": + print(app.url_map) + app.run(host="0.0.0.0") diff --git a/app/api/__init__.py b/app/api/__init__.py new file mode 100644 index 0000000..036ab13 --- /dev/null +++ b/app/api/__init__.py @@ -0,0 +1,8 @@ +"""Module containing all Flask-related code.""" +from quart import Blueprint +from .search import blueprint as search_blueprint + + +# Main blueprint exposing entire API +blueprint = Blueprint("api", __name__, url_prefix="/api") +blueprint.register_blueprint(search_blueprint) diff --git a/app/api/search.py b/app/api/search.py new file mode 100644 index 0000000..b1ca848 --- /dev/null +++ b/app/api/search.py @@ -0,0 +1,11 @@ +"""Handles the search endpoint.""" +from quart import Blueprint + + +blueprint = Blueprint("search", __name__, url_prefix="/search") + + +@blueprint.route("/", methods=["GET"]) +async def search_spotify(): + """Search the Spotify API.""" + return "yeet" diff --git a/.mocharc.yml b/web/.mocharc.yml similarity index 100% rename from .mocharc.yml rename to web/.mocharc.yml