-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
28 lines (22 loc) · 847 Bytes
/
run.py
File metadata and controls
28 lines (22 loc) · 847 Bytes
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
from app import create_app
import webbrowser
import threading
from dotenv import load_dotenv
import os
from urllib.parse import urlparse
# Load environment variables from .env file
load_dotenv()
app = create_app()
def open_browser():
api_url = os.getenv('API_URL', 'http://127.0.0.1:5000/api/swagger')
webbrowser.open_new(api_url + "/swagger")
if __name__ == "__main__":
if app.config['ENV'] == 'development':
# Start a thread to open the browser after a short delay
threading.Timer(1.25, open_browser).start()
# Extract host and port from API_URL
api_url = os.getenv('API_URL', 'http://127.0.0.1:5000/api')
parsed_url = urlparse(api_url)
host = parsed_url.hostname or '127.0.0.1'
port = parsed_url.port or 5000
app.run(debug=(app.config['ENV'] == 'development'), host=host, port=port)