humanvprojectceo commited on
Commit
cdf495f
·
verified ·
1 Parent(s): 0b4f324

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -4,26 +4,33 @@ import json
4
  import websockets
5
  from websockets.server import serve
6
 
7
- ENV_ID = os.environ.get("GOOGLE_CLIENT_ID")
8
- ENV_SECRET = os.environ.get("GOOGLE_CLIENT_SECRET")
9
- ENV_TARGET = os.environ.get("TARGET_URI")
10
- ENV_TOKEN = os.environ.get("HF_TOKEN")
 
11
 
12
  async def handler(websocket):
13
  try:
 
14
  config_data = {
15
  "google_id": ENV_ID,
16
  "google_secret": ENV_SECRET,
17
  "target_url": ENV_TARGET,
18
  "hf_token": ENV_TOKEN
19
  }
 
 
20
  await websocket.send(json.dumps(config_data))
21
- except:
22
- pass
 
 
23
  finally:
24
  await websocket.close()
25
 
26
  async def main():
 
27
  async with serve(handler, "0.0.0.0", 7860):
28
  await asyncio.Future()
29
 
 
4
  import websockets
5
  from websockets.server import serve
6
 
7
+ # دریافت متغیرها با حذف فاصله‌های احتمالی اول و آخر (strip)
8
+ ENV_ID = os.environ.get("GOOGLE_CLIENT_ID", "").strip()
9
+ ENV_SECRET = os.environ.get("GOOGLE_CLIENT_SECRET", "").strip()
10
+ ENV_TARGET = os.environ.get("TARGET_URI", "").strip()
11
+ ENV_TOKEN = os.environ.get("HF_TOKEN", "").strip()
12
 
13
  async def handler(websocket):
14
  try:
15
+ # ساختار کانفیگ ارسالی به کلاینت
16
  config_data = {
17
  "google_id": ENV_ID,
18
  "google_secret": ENV_SECRET,
19
  "target_url": ENV_TARGET,
20
  "hf_token": ENV_TOKEN
21
  }
22
+
23
+ # ارسال داده به کلاینت
24
  await websocket.send(json.dumps(config_data))
25
+ print("✅ Config sent to client.")
26
+
27
+ except Exception as e:
28
+ print(f"❌ Error sending config: {e}")
29
  finally:
30
  await websocket.close()
31
 
32
  async def main():
33
+ print("🚀 Gateway is running on port 7860")
34
  async with serve(handler, "0.0.0.0", 7860):
35
  await asyncio.Future()
36