feat(plugin): 调整插件路由前缀以避免组件冲突
将插件组件的路由前缀从 `/plugins/{plugin_name}` 修改为 `/plugins/{plugin_name}/{component_name}`。
此项更改旨在解决单个插件注册多个路由组件时可能出现的路径冲突问题,确保每个组件都拥有唯一的 API 端点。
此外,为了支持新的前端开发环境,已将端口 11451 和 3001 添加到 CORS 允许源列表中。
BREAKING CHANGE: 插件 API 的 URL 结构已发生变更。所有对插件接口的调用都需要更新为新的 `/plugins/{plugin_name}/{component_name}` 格式。
This commit is contained in:
@@ -54,8 +54,12 @@ class Server:
|
|||||||
|
|
||||||
# 配置 CORS
|
# 配置 CORS
|
||||||
origins = [
|
origins = [
|
||||||
"http://localhost:3000", # 允许的前端源
|
"http://localhost:3000",
|
||||||
"http://127.0.0.1:3000",
|
"http://127.0.0.1:3000",
|
||||||
|
"http://localhost:11451",
|
||||||
|
"http://127.0.0.1:11451",
|
||||||
|
"http://localhost:3001",
|
||||||
|
"http://127.0.0.1:3001",
|
||||||
# 在生产环境中,您应该添加实际的前端域名
|
# 在生产环境中,您应该添加实际的前端域名
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -560,7 +560,7 @@ class ComponentRegistry:
|
|||||||
component_instance = router_class()
|
component_instance = router_class()
|
||||||
server = get_global_server()
|
server = get_global_server()
|
||||||
# 生成唯一的 URL 前缀,格式为 /plugins/{plugin_name}
|
# 生成唯一的 URL 前缀,格式为 /plugins/{plugin_name}
|
||||||
prefix = f"/plugins/{info.plugin_name}"
|
prefix = f"/plugins/{info.plugin_name}/{info.name}"
|
||||||
# 将插件的路由包含到主应用中
|
# 将插件的路由包含到主应用中
|
||||||
server.app.include_router(component_instance.router, prefix=prefix, tags=[info.plugin_name])
|
server.app.include_router(component_instance.router, prefix=prefix, tags=[info.plugin_name])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user