forked from livekit-examples/python-agents-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
43 lines (36 loc) · 1.26 KB
/
Copy pathapp.py
File metadata and controls
43 lines (36 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from flask import Flask, send_from_directory, jsonify
from flask_cors import CORS
from flask_livekit import LiveKit
import os
import dotenv
import logging
from pathlib import Path
dotenv.load_dotenv(dotenv_path=Path(__file__).parent.parent / '.env')
# Configure logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
app = Flask(__name__, static_folder="frontend/dist")
CORS(app)
# Configure and initialize LiveKit
app.config.update(
LIVEKIT_API_KEY=os.getenv("LIVEKIT_API_KEY"),
LIVEKIT_API_SECRET=os.getenv("LIVEKIT_API_SECRET"),
LIVEKIT_HOST=os.getenv("LIVEKIT_HOST"),
SIP_TRUNK_ID=os.getenv("SIP_TRUNK_ID")
)
livekit = LiveKit(app)
# Error handler for 500 errors
@app.errorhandler(500)
def handle_500_error(error):
logger.error(f"Internal Server Error: {error}", exc_info=True)
return jsonify({"error": "Internal Server Error", "message": str(error)}), 500
# Serve React static files
@app.route("/", defaults={"path": ""})
@app.route("/<path:path>")
def serve(path):
if path != "" and (app.static_folder / path).exists():
return send_from_directory(app.static_folder, path)
else:
return send_from_directory(app.static_folder, "index.html")
if __name__ == "__main__":
app.run(debug=True, port=5001)