From 0d693847b1fe234491f585e9a31af0431de73123 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Tue, 18 May 2021 22:06:37 +0200 Subject: [PATCH] Flask now serves the frontend --- Dockerfile | 2 +- Makefile | 24 ++++++++++++++++-------- app/__main__.py | 10 +++++----- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2d3542a..62c4295 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,7 +47,7 @@ COPY --chown=runner:runner setup.cfg setup.py ./ COPY \ --from=fbuilder \ --chown=runner:runner \ - /usr/src/app/web/dist ./dist + /usr/src/app/web/dist ./web/dist ENTRYPOINT ["python"] CMD ["app"] diff --git a/Makefile b/Makefile index e8ccd25..6b6e2c5 100644 --- a/Makefile +++ b/Makefile @@ -8,8 +8,16 @@ MIN_COV := 0 WEB_DIR := web -# By default, just create the venv when needed +# =====GENERAL===== +## By default, create the venv all: venv +.PHONY: all + + +## Remove any temporary files +clean: + @ rm -rf '$(VENV)' '$(WEB_DIR)'/node_modules +.PHONY: clean # =====BACKEND===== @@ -44,13 +52,6 @@ test: venv .PHONY: test -## Cleaning -### Remove the venv -clean: - @ rm -rf '$(VENV)' '$(WEB_DIR)'/node_modules -.PHONY: clean - - ## Starting the server ### Run the Quart server run: venv @@ -82,6 +83,7 @@ fformat: node_modules ## Testing ftest: node_modules @ yarn --cwd '$(WEB_DIR)' test +.PHONY: ftest ## Building fbuild: node_modules @@ -94,3 +96,9 @@ fbuild: node_modules dbuild: @ DOCKER_BUILDKIT=1 docker build -t chewingbever/jos:dev . .PHONY: image + + +## Run image +drun: dbuild + @ docker run --rm -it -p 5000:5000 chewingbever/jos:dev +.PHONY: drun diff --git a/app/__main__.py b/app/__main__.py index be8dbd3..67f82e5 100644 --- a/app/__main__.py +++ b/app/__main__.py @@ -1,13 +1,13 @@ """Main entrypoint for the program.""" from quart import Quart -app = Quart("jos") +app = Quart("jos", static_folder="web/dist", static_url_path="/") -@app.route("/") -async def hello(): - """Placeholder route.""" - return "hello" +@app.route('/', methods=['GET'], defaults={'path': ''}) +@app.route('/', methods=['GET']) +async def frontend(path): + return await app.send_static_file("index.html") app.run(host="0.0.0.0")