From 97ae6ef46001ed444ef1f2bd085beae98c17c240 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Wed, 19 Jun 2024 10:39:17 -0400 Subject: [PATCH] Add api/ prefix to api endpoints (#3779) --- server.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/server.py b/server.py index bab3b060..59090258 100644 --- a/server.py +++ b/server.py @@ -527,9 +527,20 @@ class PromptServer(): self.prompt_queue.delete_history_item(id_to_delete) return web.Response(status=200) - + def add_routes(self): self.user_manager.add_routes(self.routes) + + # Prefix every route with /api for easier matching for delegation. + # This is very useful for frontend dev server, which need to forward + # everything except serving of static files. + # Currently both the old endpoints without prefix and new endpoints with + # prefix are supported. + api_routes = web.RouteTableDef() + for route in self.routes: + assert isinstance(route, web.RouteDef) + api_routes.route(route.method, "/api" + route.path)(route.handler, **route.kwargs) + self.app.add_routes(api_routes) self.app.add_routes(self.routes) for name, dir in nodes.EXTENSION_WEB_DIRS.items():