Skip to content

Commit f90f53f

Browse files
committed
Introduced a Blueprint to register routes with a configurable base path determined by the HTTP_BASE_PATH environment variable.
1 parent 188a4d3 commit f90f53f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ No matter which deployment option you chose you must setup some environment vari
4545
| `LOG_LEVEL` | The loglevel the application logs at | No | `INFO` | `DEBUG` |
4646
| `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` |
4747
| `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` |
48+
| `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` |
4849

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

source/main.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33

44
from bring_handler import BringHandler
55
from environment_variable_getter import EnvironmentVariableGetter
6-
from flask import Flask, request
6+
from flask import Blueprint, Flask, request
77
from ingredient import Ingredient, IngredientWithAmountsDisabled
88
from logger_mixin import LoggerMixin
99

1010
app = Flask(__name__)
1111

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

13-
@app.route("/", methods=["POST"])
15+
16+
@base_bp.route("/", methods=["POST"])
1417
def webhook_handler() -> str:
1518
data = request.get_json(force=True)
1619

@@ -46,7 +49,7 @@ def webhook_handler() -> str:
4649
return "OK"
4750

4851

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

7982
host = EnvironmentVariableGetter.get("HTTP_HOST", "0.0.0.0")
8083
port = int(EnvironmentVariableGetter.get("HTTP_PORT", 8742))
81-
logger.log.info(f"Listening on {host}:{port}")
84+
logger.log.info(f"Listening on {host}:{port}{basepath}")
85+
app.register_blueprint(base_bp)
8286
app.run(host=host, port=port)

0 commit comments

Comments
 (0)