better .env usage
This commit is contained in:
7
.env.example
Normal file
7
.env.example
Normal 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
27
app.py
@@ -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)
|
||||
|
||||
@@ -3,3 +3,4 @@
|
||||
|
||||
flask>=2.3.0
|
||||
flask-socketio>=5.3.0
|
||||
python-dotenv>=1.0.0
|
||||
|
||||
12
restart.sh
12
restart.sh
@@ -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
|
||||
Reference in New Issue
Block a user