From f1234937c68f5b74391454d337aae082210769d2 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 22 Apr 2023 17:30:21 +0800 Subject: [PATCH] add check path back --- config.py | 2 +- toolbox.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index f4a59de..a78af65 100644 --- a/config.py +++ b/config.py @@ -62,4 +62,4 @@ AUTHENTICATION = [] API_URL_REDIRECT = {} # 如果你需要把网址放在二级地址下(常规情况下,不要修改!!) -CUSTOM_PATH = "/gra" +CUSTOM_PATH = "/" diff --git a/toolbox.py b/toolbox.py index cd6c61e..2bf5451 100644 --- a/toolbox.py +++ b/toolbox.py @@ -522,6 +522,25 @@ class DummyWith(): return def run_gradio(demo, auth, port, custom_path): + def is_path_legal(path: str)->bool: + ''' + check path for sub url + path: path to check + return value: do sub url wrap + ''' + if path == "/": return True + if len(path) == 0: + print("ilegal custom path: {}\npath must not be empty\ndeploy on root url".format(path)) + return False + if path[0] == '/': + if path[1] != '/': + print("deploy on sub-path {}".format(path)) + return True + return False + print("ilegal custom path: {}\npath should begin with \'/\'\ndeploy on root url".format(path)) + return False + + if not is_path_legal(custom_path): raise RuntimeError('Ilegal custom path') import uvicorn import gradio as gr from fastapi import FastAPI