Skip to content

Commit

Permalink
fix: web-app directory for flask and redirect /?data=data to /api?dat…
Browse files Browse the repository at this point in the history
…a=data
  • Loading branch information
Thibault Ballier committed Oct 6, 2023
1 parent 0aadadf commit f2aec59
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN cd web-app && pnpm install && pnpm build

RUN mv ./web-app/build ./temp-build \
&& rm -rf ./web-app \
&& mkdir -p ./web-app \
&& mkdir -p ./web-app/ \
&& mv ./temp-build ./web-app/build


Expand All @@ -21,7 +21,7 @@ FROM python:3.11.4-slim-bullseye
WORKDIR /app
COPY . .
RUN rm -rf web-app
COPY --from=build-web-app /app/web-app/build /app/web-app/
COPY --from=build-web-app /app/web-app/build /app/web-app/build
RUN pip install -r requirements.txt

CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--access-logfile", "/logs/access.log", "--error-logfile", "/logs/error.log", "app:app"]
10 changes: 8 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ def list_teams() -> flask.Response:


@app.route("/api")
def main_request_handler() -> flask.Response:
def main_request_api_handler() -> flask.Response:
if os.environ.get("DEBUG"):
return request_handler()

try:
return request_handler()
except Exception as e:
Expand All @@ -66,6 +65,13 @@ def main_request_handler() -> flask.Response:

@app.route("/")
def serve_static_index() -> flask.Response:
data = flask.request.args.get("data", None)
if data is not None:
# Redirect user to /api if data is passed to keep compatibility
redirect_route = flask.url_for('main_request_api_handler')
redirect_url = f"{redirect_route}?data={data}"
return flask.redirect(redirect_url)

return send_from_directory("web-app/build", "index.html")


Expand Down

0 comments on commit f2aec59

Please sign in to comment.