From 95c49c59247ba8f7e2ec7b1b35e1c0f699b3a174 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Tue, 27 Aug 2024 13:02:01 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E2=80=94=20Allow=20to=20run=20Argo?= =?UTF-8?q?s=20in=20a=20subfolder=20(i.e.=20not=20on=20/).=20Fix=20#59?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + argos/config-example.yaml | 5 +++++ argos/schemas/config.py | 1 + argos/server/main.py | 12 ++++++++++-- conf/nginx-subdirectory.conf | 4 ++++ docs/deployment/nginx.md | 8 ++++++++ 6 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 conf/nginx-subdirectory.conf diff --git a/CHANGELOG.md b/CHANGELOG.md index f6f98a3..ab2681e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - ✨ — Add new check types: headers-contain and headers-have - ✨ — Add command to test email configuration (!66) - 💄 — Enhance the mobile view (!67) +- ✨ — Allow to run Argos in a subfolder (i.e. not on /) (#59) ## 0.2.2 diff --git a/argos/config-example.yaml b/argos/config-example.yaml index dacbed8..286b9fc 100644 --- a/argos/config-example.yaml +++ b/argos/config-example.yaml @@ -33,6 +33,11 @@ general: - local unknown: - local + # Argos root path + # If not present, default value is "" + # Set it to /foo if you want to use argos at /foo/ instead of / + # on your web server + # root_path: "/foo" # Mail configuration is quite straight-forward # mail: # mailfrom: no-reply@example.org diff --git a/argos/schemas/config.py b/argos/schemas/config.py index 4bb9f1e..f4887ca 100644 --- a/argos/schemas/config.py +++ b/argos/schemas/config.py @@ -164,6 +164,7 @@ class General(BaseModel): frequency: int db: DbSettings env: Environment = "production" + root_path: str = "" alerts: Alert mail: Optional[Mail] = None gotify: Optional[List[GotifyUrl]] = None diff --git a/argos/server/main.py b/argos/server/main.py index 898b202..b6ee412 100644 --- a/argos/server/main.py +++ b/argos/server/main.py @@ -18,11 +18,19 @@ from argos.server.settings import read_yaml_config def get_application() -> FastAPI: """Spawn Argos FastAPI server""" - appli = FastAPI(lifespan=lifespan) config_file = os.environ["ARGOS_YAML_FILE"] - config = read_config(config_file) + root_path = config.general.root_path + + if root_path != "": + logger.info("Root path for Argos: %s", root_path) + if root_path.endswith("/"): + root_path = root_path[:-1] + logger.info("Fixed root path for Argos: %s", root_path) + + appli = FastAPI(lifespan=lifespan, root_path=root_path) + # Config is the argos config object (built from yaml) appli.state.config = config appli.add_exception_handler(NotAuthenticatedException, auth_exception_handler) diff --git a/conf/nginx-subdirectory.conf b/conf/nginx-subdirectory.conf new file mode 100644 index 0000000..92f95b7 --- /dev/null +++ b/conf/nginx-subdirectory.conf @@ -0,0 +1,4 @@ +location /foo/ { + include proxy_params; + proxy_pass http://127.0.0.1:8000/; +} diff --git a/docs/deployment/nginx.md b/docs/deployment/nginx.md index 25af5be..310f090 100644 --- a/docs/deployment/nginx.md +++ b/docs/deployment/nginx.md @@ -6,3 +6,11 @@ Here is a example for Nginx configuration: caption: /etc/nginx/sites-available/argos.example.org --- ``` + +If you want to use Argos under a subdirectory of your web server, you’ll need to set the `root_path` setting in Argos’s [configuration](../configuration.md) and set Nginx like this: + +```{literalinclude} ../../conf/nginx-subdirectory.conf +--- +caption: Nginx’s location for Argos in a subdirectory +--- +```