Skip to content

Commit

Permalink
support ipv6 (#850)
Browse files Browse the repository at this point in the history
* support ipv6

There are many `:` in ipv6 address, uvicorn is support both v6 and v4, but `host, port = api.args.listen.split(":")` this line will fail to split v6 host

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
TITC and pre-commit-ci[bot] authored Jan 23, 2025
1 parent 9ff5c11 commit 7d74951
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tools/api_server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from threading import Lock

import pyrootutils
Expand Down Expand Up @@ -98,9 +99,14 @@ async def initialize_app(self, app: Kui):
# Instead, it's better to use multiprocessing or independent models per thread.

if __name__ == "__main__":

api = API()
host, port = api.args.listen.split(":")

# IPv6 address format is [xxxx:xxxx::xxxx]:port
match = re.search(r"\[([^\]]+)\]:(\d+)$", api.args.listen)
if match:
host, port = match.groups() # IPv6
else:
host, port = api.args.listen.split(":") # IPv4

uvicorn.run(
api.app,
Expand Down

0 comments on commit 7d74951

Please sign in to comment.