mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-11-20 21:37:00 +08:00
Add support for url_prefix
This commit is contained in:
parent
746a0410d4
commit
8c90348a80
@ -39,6 +39,7 @@ parser.add_argument("--tls-keyfile", type=str, help="Path to TLS (SSL) key file.
|
||||
parser.add_argument("--tls-certfile", type=str, help="Path to TLS (SSL) certificate file. Enables TLS, makes app accessible at https://... requires --tls-keyfile to function")
|
||||
parser.add_argument("--enable-cors-header", type=str, default=None, metavar="ORIGIN", nargs="?", const="*", help="Enable CORS (Cross-Origin Resource Sharing) with optional origin or allow all with default '*'.")
|
||||
parser.add_argument("--max-upload-size", type=float, default=100, help="Set the maximum upload size in MB.")
|
||||
parser.add_argument("--url-prefix", type=str, default="", help="Specify a URL prefix for the server.")
|
||||
|
||||
parser.add_argument("--extra-model-paths-config", type=str, default=None, metavar="PATH", nargs='+', action='append', help="Load one or more extra_model_paths.yaml files.")
|
||||
parser.add_argument("--output-directory", type=str, default=None, help="Set the ComfyUI output directory.")
|
||||
|
||||
4
main.py
4
main.py
@ -203,7 +203,7 @@ if __name__ == "__main__":
|
||||
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
server = server.PromptServer(loop)
|
||||
server = server.PromptServer(loop, url_prefix=args.url_prefix)
|
||||
q = execution.PromptQueue(server)
|
||||
|
||||
extra_model_paths_config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "extra_model_paths.yaml")
|
||||
@ -247,7 +247,7 @@ if __name__ == "__main__":
|
||||
import webbrowser
|
||||
if os.name == 'nt' and address == '0.0.0.0':
|
||||
address = '127.0.0.1'
|
||||
webbrowser.open(f"{scheme}://{address}:{port}")
|
||||
webbrowser.open(f"{scheme}://{address}:{port}/{args.url_prefix}/")
|
||||
call_on_start = startup_server
|
||||
|
||||
try:
|
||||
|
||||
25
server.py
25
server.py
@ -62,8 +62,9 @@ def create_cors_middleware(allowed_origin: str):
|
||||
return cors_middleware
|
||||
|
||||
class PromptServer():
|
||||
def __init__(self, loop):
|
||||
def __init__(self, loop, url_prefix=""):
|
||||
PromptServer.instance = self
|
||||
self.url_prefix = url_prefix
|
||||
|
||||
mimetypes.init()
|
||||
mimetypes.types_map['.js'] = 'application/javascript; charset=utf-8'
|
||||
@ -81,6 +82,8 @@ class PromptServer():
|
||||
|
||||
max_upload_size = round(args.max_upload_size * 1024 * 1024)
|
||||
self.app = web.Application(client_max_size=max_upload_size, middlewares=middlewares)
|
||||
if self.url_prefix:
|
||||
self.sub_app = web.Application(client_max_size=max_upload_size, middlewares=middlewares)
|
||||
self.sockets = dict()
|
||||
self.web_root = os.path.join(os.path.dirname(
|
||||
os.path.realpath(__file__)), "web")
|
||||
@ -529,18 +532,23 @@ class PromptServer():
|
||||
return web.Response(status=200)
|
||||
|
||||
def add_routes(self):
|
||||
app = self.sub_app if self.url_prefix else self.app
|
||||
|
||||
self.user_manager.add_routes(self.routes)
|
||||
self.app.add_routes(self.routes)
|
||||
app.add_routes(self.routes)
|
||||
|
||||
for name, dir in nodes.EXTENSION_WEB_DIRS.items():
|
||||
self.app.add_routes([
|
||||
web.static('/extensions/' + urllib.parse.quote(name), dir),
|
||||
app.add_routes([
|
||||
web.static(f'/extensions/' + urllib.parse.quote(name), dir),
|
||||
])
|
||||
|
||||
self.app.add_routes([
|
||||
web.static('/', self.web_root),
|
||||
app.add_routes([
|
||||
web.static(f'/', self.web_root),
|
||||
])
|
||||
|
||||
if self.url_prefix:
|
||||
self.app.add_subapp(f'/{self.url_prefix}', self.sub_app)
|
||||
|
||||
def get_queue_info(self):
|
||||
prompt_info = {}
|
||||
exec_info = {}
|
||||
@ -637,7 +645,10 @@ class PromptServer():
|
||||
|
||||
if verbose:
|
||||
logging.info("Starting server\n")
|
||||
logging.info("To see the GUI go to: {}://{}:{}".format(scheme, address, port))
|
||||
prefix = self.url_prefix
|
||||
if self.url_prefix:
|
||||
prefix = f"{self.url_prefix}/"
|
||||
logging.info("To see the GUI go to: {}://{}:{}/{}".format(scheme, address, port, prefix))
|
||||
if call_on_start is not None:
|
||||
call_on_start(scheme, address, port)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user