mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-04 13:02:09 +08:00
add helper for serving a directory (#31802)
directory http server old-commit-hash: 358461896c115027a6372504505a4cd9be8dbeb2
This commit is contained in:
@@ -113,3 +113,12 @@ def with_http_server(func, handler=http.server.BaseHTTPRequestHandler, setup=Non
|
||||
with http_server_context(handler, setup) as (host, port):
|
||||
return func(*args, f"http://{host}:{port}", **kwargs)
|
||||
return inner
|
||||
|
||||
|
||||
def DirectoryHttpServer(directory) -> type[http.server.SimpleHTTPRequestHandler]:
|
||||
# creates an http server that serves files from directory
|
||||
class Handler(http.server.SimpleHTTPRequestHandler):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, directory=str(directory), **kwargs)
|
||||
|
||||
return Handler
|
||||
|
||||
Reference in New Issue
Block a user