Skip to content

Commit

Permalink
Introduced a Blueprint to register routes with a configurable base pa…
Browse files Browse the repository at this point in the history
…th determined by the `HTTP_BASE_PATH` environment variable.
  • Loading branch information
felixschndr committed Mar 9, 2025
1 parent 188a4d3 commit f90f53f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ No matter which deployment option you chose you must setup some environment vari
| `LOG_LEVEL` | The loglevel the application logs at | No | `INFO` | `DEBUG` |
| `HTTP_HOST` | The address the application tries to attach to, leave this empty to listen on all interfaces, leave this empty if you are using Docker | No | `0.0.0.0` | `192.168.1.5` |
| `HTTP_PORT` | The port the application listens on, change this if needed if you run the application locally, leave this empty if you are using Docker | No | `8742` | `1234` |
| `HTTP_BASE_PATH` | The path the application listens on. Use this if you use the app behind a reverse proxy and have setup a path (e.g. set this to `/bring` if the application shall listen on `<mealie>.<yourdomain>.tld/bring`) | No | `""` | `/bring` |

Ensure to quote your environment variables. Without quotes your password might not be read properly if it contains symbols such as `<`, `&` or `;`.

Expand Down
12 changes: 8 additions & 4 deletions source/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@

from bring_handler import BringHandler
from environment_variable_getter import EnvironmentVariableGetter
from flask import Flask, request
from flask import Blueprint, Flask, request
from ingredient import Ingredient, IngredientWithAmountsDisabled
from logger_mixin import LoggerMixin

app = Flask(__name__)

basepath = EnvironmentVariableGetter.get("HTTP_BASE_PATH", "")
base_bp = Blueprint("base_bp", __name__, url_prefix=f"{basepath}")

@app.route("/", methods=["POST"])

@base_bp.route("/", methods=["POST"])
def webhook_handler() -> str:
data = request.get_json(force=True)

Expand Down Expand Up @@ -46,7 +49,7 @@ def webhook_handler() -> str:
return "OK"


@app.route("/status", methods=["GET"])
@base_bp.route("/status", methods=["GET"])
def status_handler() -> str:
logger.log.debug("Got a status request")
return "OK"
Expand Down Expand Up @@ -78,5 +81,6 @@ def parse_ignored_ingredients() -> list[Ingredient]:

host = EnvironmentVariableGetter.get("HTTP_HOST", "0.0.0.0")
port = int(EnvironmentVariableGetter.get("HTTP_PORT", 8742))
logger.log.info(f"Listening on {host}:{port}")
logger.log.info(f"Listening on {host}:{port}{basepath}")
app.register_blueprint(base_bp)
app.run(host=host, port=port)

0 comments on commit f90f53f

Please sign in to comment.