Add api/ prefix to api endpoints (#3779)

This commit is contained in:
Chenlei Hu 2024-06-19 10:39:17 -04:00 committed by GitHub
parent 3914d5a2ae
commit 97ae6ef460
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 1 deletions

View File

@ -530,6 +530,17 @@ class PromptServer():
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():