more env variables

This commit is contained in:
Gamosoft 2026-06-30 17:07:51 +02:00
parent 12ed9bd3e9
commit dfbc22075a
3 changed files with 44 additions and 16 deletions

View File

@ -146,6 +146,20 @@ if config.get('authentication', {}).get('enabled', False):
if _is_default_secret: if _is_default_secret:
logger.critical("Using default secret_key - sessions can be forged! Change it in config.yaml") logger.critical("Using default secret_key - sessions can be forged! Change it in config.yaml")
# Storage paths: env vars override config.yaml. Logged either way so the
# resolved location is visible at startup.
_notes_source = "config.yaml"
if 'NOTES_DIR' in os.environ:
config['storage']['notes_dir'] = os.getenv('NOTES_DIR')
_notes_source = "NOTES_DIR env var"
logger.info("Notes directory: %s (from %s)", config['storage']['notes_dir'], _notes_source)
_plugins_source = "config.yaml"
if 'PLUGINS_DIR' in os.environ:
config['storage']['plugins_dir'] = os.getenv('PLUGINS_DIR')
_plugins_source = "PLUGINS_DIR env var"
logger.info("Plugins directory: %s (from %s)", config['storage']['plugins_dir'], _plugins_source)
# OpenAPI tag metadata for grouping endpoints in Swagger UI # OpenAPI tag metadata for grouping endpoints in Swagger UI
tags_metadata = [ tags_metadata = [
{"name": "Notes", "description": "Create, read, update, delete notes"}, {"name": "Notes", "description": "Create, read, update, delete notes"},

View File

@ -12,6 +12,30 @@ NoteDiscovery supports environment variables to override configuration settings,
> **Note**: Advanced server settings (CORS origins, debug mode) are configured via `config.yaml` only, not via environment variables. See [config.yaml](#advanced-server-configuration) for details. > **Note**: Advanced server settings (CORS origins, debug mode) are configured via `config.yaml` only, not via environment variables. See [config.yaml](#advanced-server-configuration) for details.
### Storage
| Variable | Type | Default | Description |
|----------|------|---------|-------------|
| `NOTES_DIR` | string | `./data` | Path to the notes vault |
| `PLUGINS_DIR` | string | `./plugins` | Path to the plugins directory |
The resolved paths are logged at startup so you can confirm what's in use:
```
INFO: Notes directory: /home/me/MyVault (from NOTES_DIR env var)
INFO: Plugins directory: ./plugins (from config.yaml)
```
#### Example: Pointing at an existing vault
```bash
# Local
NOTES_DIR=/home/me/MyVault python run.py
# Docker
docker run -e NOTES_DIR=/vault -v /home/me/MyVault:/vault ...
```
### Authentication ### Authentication
| Variable | Type | Default | Description | | Variable | Type | Default | Description |

22
run.py
View File

@ -16,26 +16,21 @@ except ImportError:
colorama = None colorama = None
def get_port(): def get_port():
"""Get port from: 1) ENV variable, 2) config.yaml, 3) default 8000""" """Get port from: 1) PORT env var, 2) config.yaml, 3) default 8000."""
# Priority 1: Environment variable
if os.getenv("PORT"): if os.getenv("PORT"):
return os.getenv("PORT") return os.getenv("PORT")
# Priority 2: config.yaml
config_path = Path("config.yaml") config_path = Path("config.yaml")
if config_path.exists(): if config_path.exists():
try: try:
import yaml import yaml
with open(config_path, 'r', encoding='utf-8') as f: with open(config_path, 'r', encoding='utf-8') as f:
config = yaml.safe_load(f) cfg = yaml.safe_load(f) or {}
if config and 'server' in config and 'port' in config['server']: return str(cfg.get('server', {}).get('port', 8000))
return str(config['server']['port'])
except Exception: except Exception:
pass # Fall through to default pass
# Priority 3: Default
return "8000" return "8000"
def main(): def main():
try: try:
import fastapi # noqa: F401 import fastapi # noqa: F401
@ -44,13 +39,8 @@ def main():
print("Installing dependencies...") print("Installing dependencies...")
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"]) subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
Path("data").mkdir(parents=True, exist_ok=True)
Path("plugins").mkdir(parents=True, exist_ok=True)
port = get_port() port = get_port()
print(f"🚀 NoteDiscovery → http://localhost:{port} (Ctrl+C to stop)")
print(f"🚀 NoteDiscovery → http://localhost:{port}")
print(f" notes: ./data/ plugins: ./plugins/ stop: Ctrl+C")
print() print()
subprocess.call([ subprocess.call([