bind 0.0.0.0

This commit is contained in:
2026-09-22 11:09:33 +08:00
parent 2006f7b4a4
commit d9ff32d2bb
3 changed files with 8 additions and 4 deletions

View File

@@ -11,7 +11,8 @@ pip install -r requirements.txt
python3 -m app python3 -m app
``` ```
浏览器打开 http://127.0.0.1:8765 浏览器打开 http://服务器IP:8765 (本机也可用 http://127.0.0.1:8765)
服务默认监听 `0.0.0.0:8765`。可用环境变量覆盖:`HOST=127.0.0.1 PORT=8765 ./run.sh`
默认账号:`admin` / `hangbiao2026`(请在 `app/config.py` 修改) 默认账号:`admin` / `hangbiao2026`(请在 `app/config.py` 修改)

View File

@@ -5,7 +5,7 @@ import uvicorn
if __name__ == "__main__": if __name__ == "__main__":
uvicorn.run( uvicorn.run(
"app.main:app", "app.main:app",
host="127.0.0.1", host=os.environ.get("HOST", "0.0.0.0"),
port=int(os.environ.get("PORT", "8765")), port=int(os.environ.get("PORT", "8765")),
reload=os.environ.get("RELOAD", "1") != "0", reload=os.environ.get("RELOAD", "0") != "0",
) )

5
run.sh
View File

@@ -1,8 +1,11 @@
#!/bin/zsh #!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")" cd "$(dirname "$0")"
if [ ! -x .venv/bin/python ]; then if [ ! -x .venv/bin/python ]; then
python3 -m venv .venv python3 -m venv .venv
.venv/bin/pip install -r requirements.txt .venv/bin/pip install -r requirements.txt
fi fi
export HOST="${HOST:-0.0.0.0}"
export PORT="${PORT:-8765}" export PORT="${PORT:-8765}"
export RELOAD="${RELOAD:-0}"
exec .venv/bin/python -m app exec .venv/bin/python -m app