better .env usage

This commit is contained in:
2026-05-03 21:30:52 +00:00
parent 463bfb48a5
commit 8a239cbd28
5 changed files with 11 additions and 39 deletions

7
.env.example Normal file
View File

@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# ClaudeWebUI - Developed by acidvegas in Python (https://github.com/acidvegas)
# claudewebui/.env.example
HOST=0.0.0.0
PORT=5005
WEBUI_PASSWORD=changeme

27
app.py
View File

@@ -22,35 +22,14 @@ from datetime import datetime, timedelta, timezone
from functools import wraps
from pathlib import Path
from dotenv import load_dotenv
from flask import (Flask, jsonify, redirect, render_template, request, abort,
send_file, session as flask_session, url_for)
from flask_socketio import SocketIO, emit, join_room, leave_room
# ---------- .env loader (no extra dep) ----------
def _load_dotenv(path):
if not os.path.isfile(path):
return
try:
with open(path) as f:
for line in f:
line = line.strip()
if not line or line.startswith('#') or '=' not in line:
continue
k, v = line.split('=', 1)
k = k.strip()
v = v.strip()
if (v.startswith('"') and v.endswith('"')) or \
(v.startswith("'") and v.endswith("'")):
v = v[1:-1]
os.environ.setdefault(k, v)
except OSError:
pass
_APP_DIR = os.path.dirname(os.path.abspath(__file__))
_load_dotenv(os.path.join(_APP_DIR, '.env'))
load_dotenv(os.path.join(_APP_DIR, '.env'))
WEBUI_PASSWORD = os.environ.get('WEBUI_PASSWORD') or 'loldongs'
@@ -1341,7 +1320,7 @@ def resume_session():
if __name__ == '__main__':
port = int(os.environ.get('PORT', 61234))
port = int(os.environ.get('PORT', 5005))
host = os.environ.get('HOST', '0.0.0.0')
print(f'Claude Code Web IDE → http://{host}:{port}')
socketio.run(app, host=host, port=port, debug=False, allow_unsafe_werkzeug=True)

View File

@@ -3,3 +3,4 @@
flask>=2.3.0
flask-socketio>=5.3.0
python-dotenv>=1.0.0

View File

@@ -1,12 +0,0 @@
#!/usr/bin/env bash
# Restart the Claude Web UI server. Always-stable single-string command,
# safe to auto-approve once.
set -u
ROOT="$(cd "$(dirname "$0")" && pwd)"
pkill -f "${ROOT}/app.py" 2>/dev/null || true
sleep 1
nohup "${ROOT}/.venv/bin/python" "${ROOT}/app.py" \
>/tmp/webui.log 2>&1 </dev/null &
disown
sleep 2
tail -3 /tmp/webui.log

View File

@@ -14,7 +14,4 @@ source .venv/bin/activate
pip install -q -r requirements.txt
PORT=${PORT:-45000}
HOST=10.30.0.10
echo "Starting Claude Code Web IDE on http://localhost:$PORT"
python3 app.py