add check path back

This commit is contained in:
Your Name 2023-04-22 17:30:21 +08:00
parent 7beea951c6
commit f1234937c6
2 changed files with 20 additions and 1 deletions

View File

@ -62,4 +62,4 @@ AUTHENTICATION = []
API_URL_REDIRECT = {}
# 如果你需要把网址放在二级地址下(常规情况下,不要修改!!)
CUSTOM_PATH = "/gra"
CUSTOM_PATH = "/"

View File

@ -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