> ## Documentation Index
> Fetch the complete documentation index at: https://dripart-train-lora-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 路由

## 路由

服务器定义了一系列 `get` 和 `post` 方法，
这些方法可以通过在 `server.py` 中搜索 `@routes` 找到。当你在网页客户端提交工作流时，
它会被发送到 `/prompt` 端点，该端点会验证提示并将其添加到执行队列中，
返回 `prompt_id` 和 `number`（队列中的位置），如果验证失败则返回 `error` 和 `node_errors`。
提示队列定义在 `execution.py` 中，该文件还定义了 `PromptExecutor` 类。

### 内置路由

`server.py` 定义了以下路由：

| 路径                             | get/post | 用途                                                 |
| ------------------------------ | -------- | -------------------------------------------------- |
| `/`                            | get      | 加载 Comfy 网页                                        |
| `/embeddings`                  | get      | 获取可用的嵌入模型名称列表                                      |
| `/extensions`                  | get      | 获取注册了 `WEB_DIRECTORY` 的扩展列表                        |
| `/workflow_templates`          | get      | 获取自定义节点模块及其关联模板工作流的映射                              |
| `/upload/image`                | post     | 上传图片                                               |
| `/upload/mask`                 | post     | 上传蒙版                                               |
| `/view`                        | get      | 查看图片。更多选项请参见 `server.py` 中的 `@routes.get("/view")` |
| `/view_metadata`/{folder_name} | get      | 获取模型的元数据                                           |
| `/system_stats`                | get      | 获取系统信息（Python 版本、设备、显存等）                           |
| `/prompt`                      | get      | 获取当前状态                                             |
| `/prompt`                      | post     | 提交提示到队列                                            |
| `/object_info`                 | get      | 获取所有节点类型的详细信息                                      |
| `/object_info/{node_class}`    | get      | 获取特定节点类型的详细信息                                      |
| `/history`                     | get      | 获取队列历史记录                                           |
| `/history/{prompt_id}`         | get      | 获取特定提示的队列历史记录                                      |
| `/history`                     | post     | 清除历史记录或删除历史记录项                                     |
| `/queue`                       | get      | 获取队列状态                                             |
| `/interrupt`                   | post     | 停止当前工作流                                            |
| `/free`                        | post     | 通过卸载指定模型释放内存                                       |

### 自定义路由

如果你想在执行过程中从客户端向服务器发送消息，你需要在服务器中添加一个自定义路由。
对于复杂的情况，你需要深入研究 [aiohttp 框架文档](https://docs.aiohttp.org/)，但大多数情况可以按以下方式处理：

```Python
from server import PromptServer
from aiohttp import web
routes = PromptServer.instance.routes
@routes.post('/my_new_path')
async def my_function(request):
    the_data = await request.post()
    # the_data now holds a dictionary of the values sent
    MyClass.handle_my_message(the_data)
    return web.json_response({})
```

<Tip>
  除非你确切知道自己在做什么，否则不要尝试在类中定义 `my_function`。
  `@routes.post` 装饰器做了很多工作！相反，应该像上面那样定义函数，
  然后调用一个类方法。
</Tip>

<Tip>
  如果你不需要修改任何内容，也可以定义 `@routes.get`。
</Tip>

客户端可以通过发送 `FormData` 对象来使用这个新路由，代码如下所示，
这将导致上面代码中的 `the_data` 包含 `message` 和 `node_id` 键：

```Javascript
import { api } from "../../scripts/api.js";
function send_message(node_id, message) {
    const body = new FormData();
    body.append('message',message);
    body.append('node_id', node_id);
    api.fetchApi("/my_new_path", { method: "POST", body, });
}
```
