Files
baiyue-logistics-chat/logistics_chat/runtime.py
T

34 lines
985 B
Python
Raw Normal View History

"""Explicit local serving entry point; importing it starts no server."""
def local_ips():
import socket
ips = set()
try:
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as connection:
connection.connect(('8.8.8.8', 80))
ips.add(connection.getsockname()[0])
except Exception:
pass
try:
for info in socket.getaddrinfo(socket.gethostname(), None, socket.AF_INET):
ip = info[4][0]
if not ip.startswith('127.'):
ips.add(ip)
except Exception:
pass
return sorted(ips)
def serve_app(app):
host, port = app.config['HOST'], app.config['PORT']
print(f'Local: http://127.0.0.1:{port}')
for ip in local_ips():
print(f'LAN: http://{ip}:{port}')
try:
from waitress import serve
except ImportError:
app.run(host=host, port=port, debug=True, use_reloader=False)
else:
serve(app, host=host, port=port, threads=8)