more env variables
This commit is contained in:
parent
12ed9bd3e9
commit
dfbc22075a
|
|
@ -146,6 +146,20 @@ if config.get('authentication', {}).get('enabled', False):
|
|||
if _is_default_secret:
|
||||
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
|
||||
tags_metadata = [
|
||||
{"name": "Notes", "description": "Create, read, update, delete notes"},
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
### 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
|
||||
|
||||
| Variable | Type | Default | Description |
|
||||
|
|
|
|||
22
run.py
22
run.py
|
|
@ -16,26 +16,21 @@ except ImportError:
|
|||
colorama = None
|
||||
|
||||
def get_port():
|
||||
"""Get port from: 1) ENV variable, 2) config.yaml, 3) default 8000"""
|
||||
# Priority 1: Environment variable
|
||||
"""Get port from: 1) PORT env var, 2) config.yaml, 3) default 8000."""
|
||||
if os.getenv("PORT"):
|
||||
return os.getenv("PORT")
|
||||
|
||||
# Priority 2: config.yaml
|
||||
config_path = Path("config.yaml")
|
||||
if config_path.exists():
|
||||
try:
|
||||
import yaml
|
||||
with open(config_path, 'r', encoding='utf-8') as f:
|
||||
config = yaml.safe_load(f)
|
||||
if config and 'server' in config and 'port' in config['server']:
|
||||
return str(config['server']['port'])
|
||||
cfg = yaml.safe_load(f) or {}
|
||||
return str(cfg.get('server', {}).get('port', 8000))
|
||||
except Exception:
|
||||
pass # Fall through to default
|
||||
|
||||
# Priority 3: Default
|
||||
pass
|
||||
return "8000"
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
import fastapi # noqa: F401
|
||||
|
|
@ -44,13 +39,8 @@ def main():
|
|||
print("Installing dependencies...")
|
||||
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()
|
||||
|
||||
print(f"🚀 NoteDiscovery → http://localhost:{port}")
|
||||
print(f" notes: ./data/ plugins: ./plugins/ stop: Ctrl+C")
|
||||
print(f"🚀 NoteDiscovery → http://localhost:{port} (Ctrl+C to stop)")
|
||||
print()
|
||||
|
||||
subprocess.call([
|
||||
|
|
|
|||
Loading…
Reference in New Issue