— Allow to run Argos in a subfolder (i.e. not on /). Fix #59

This commit is contained in:
Luc Didry 2024-08-27 13:02:01 +02:00
parent bc3bc52ed0
commit 95c49c5924
No known key found for this signature in database
GPG key ID: EA868E12D0257E3C
6 changed files with 29 additions and 2 deletions

View file

@ -9,6 +9,7 @@
- ✨ — Add new check types: headers-contain and headers-have - ✨ — Add new check types: headers-contain and headers-have
- ✨ — Add command to test email configuration (!66) - ✨ — Add command to test email configuration (!66)
- 💄 — Enhance the mobile view (!67) - 💄 — Enhance the mobile view (!67)
- ✨ — Allow to run Argos in a subfolder (i.e. not on /) (#59)
## 0.2.2 ## 0.2.2

View file

@ -33,6 +33,11 @@ general:
- local - local
unknown: unknown:
- local - 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 configuration is quite straight-forward
# mail: # mail:
# mailfrom: no-reply@example.org # mailfrom: no-reply@example.org

View file

@ -164,6 +164,7 @@ class General(BaseModel):
frequency: int frequency: int
db: DbSettings db: DbSettings
env: Environment = "production" env: Environment = "production"
root_path: str = ""
alerts: Alert alerts: Alert
mail: Optional[Mail] = None mail: Optional[Mail] = None
gotify: Optional[List[GotifyUrl]] = None gotify: Optional[List[GotifyUrl]] = None

View file

@ -18,11 +18,19 @@ from argos.server.settings import read_yaml_config
def get_application() -> FastAPI: def get_application() -> FastAPI:
"""Spawn Argos FastAPI server""" """Spawn Argos FastAPI server"""
appli = FastAPI(lifespan=lifespan)
config_file = os.environ["ARGOS_YAML_FILE"] config_file = os.environ["ARGOS_YAML_FILE"]
config = read_config(config_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) # Config is the argos config object (built from yaml)
appli.state.config = config appli.state.config = config
appli.add_exception_handler(NotAuthenticatedException, auth_exception_handler) appli.add_exception_handler(NotAuthenticatedException, auth_exception_handler)

View file

@ -0,0 +1,4 @@
location /foo/ {
include proxy_params;
proxy_pass http://127.0.0.1:8000/;
}

View file

@ -6,3 +6,11 @@ Here is a example for Nginx configuration:
caption: /etc/nginx/sites-available/argos.example.org caption: /etc/nginx/sites-available/argos.example.org
--- ---
``` ```
If you want to use Argos under a subdirectory of your web server, youll need to set the `root_path` setting in Argoss [configuration](../configuration.md) and set Nginx like this:
```{literalinclude} ../../conf/nginx-subdirectory.conf
---
caption: Nginxs location for Argos in a subdirectory
---
```