Skip to content

Commit

Permalink
Fixed issue with Flask env
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomansion committed Jul 22, 2024
1 parent 9cf823f commit 2331a47
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ COPY debiaiServer/ debiaiServer/
RUN pip install --trusted-host pypi.python.org -r debiaiServer/requirements.txt
COPY run_debiai_server_prod.py .
COPY --from=build-stage /frontend/dist debiaiServer/dist
ENV FLASK_ENV production
CMD ["python", "run_debiai_server_prod.py"]

15 changes: 6 additions & 9 deletions debiaiServer/websrv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import psutil
import requests
import connexion
Expand All @@ -18,14 +17,12 @@
CORS(app.app)


def send_frontend(path):
def send_frontend(path, is_dev):
if path == "/":
path = "index.html"

# If production, use the index.html from the dist folder
env = os.getenv("FLASK_ENV", "production")
debug_mode = env == "production"
if debug_mode:
if not is_dev:
return send_from_directory("dist", path)

# In development, redirect to the DEV_FRONTEND_URL
Expand Down Expand Up @@ -57,16 +54,16 @@ def send_frontend(path):
print("Unexpected request method")


def create_app():
def create_app(is_dev):
# For serving the dashboard
@app.route("/")
def send_index():
return send_frontend("/")
return send_frontend("/", is_dev)

# For serving the dashboard assets
@app.route("/<path:path>")
def send_supporting_elements(path):
return send_frontend(path)
return send_frontend(path, is_dev)

return app

Expand Down Expand Up @@ -102,7 +99,7 @@ def start_server(port, reloader=True, is_dev=True):
+ colored("http://localhost:" + str(port), DEBUG_COLOR),
flush=True,
)
app = create_app()
app = create_app(is_dev)
if is_dev:
# Use flask server for development
app.run(port, debug=True, host="0.0.0.0", use_reloader=reloader)
Expand Down

0 comments on commit 2331a47

Please sign in to comment.