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:
minecraft1024a
2025-12-05 19:15:14 +08:00
parent fa8555aeb7
commit b8bbd7228f
2 changed files with 6 additions and 2 deletions

View File

@@ -54,8 +54,12 @@ class Server:
# 配置 CORS
origins = [
"http://localhost:3000", # 允许的前端源
"http://localhost: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",
# 在生产环境中,您应该添加实际的前端域名
]

View File

@@ -560,7 +560,7 @@ class ComponentRegistry:
component_instance = router_class()
server = get_global_server()
# 生成唯一的 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])