| 12345678910111213141516171819202122232425 |
- import uvicorn
- from app.core.config import settings
- import socket
- def get_host_ip():
- """
- 查询本机ip地址
- """
- try:
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- s.connect(('8.8.8.8', 80))
- ip = s.getsockname()[0]
- except Exception:
- # 如果没有网络,回退到 host name
- ip = socket.gethostbyname(socket.gethostname())
- finally:
- s.close()
- return ip
- if __name__ == '__main__':
- ip = get_host_ip()
- print(f" Docs available at: http://{ip}:{settings.app.port}/docs")
- uvicorn.run("app.main:app", host=settings.app.host, port=settings.app.port, reload=True)
|