Flow ServerStarter
存储与消息

CORS 响应头

type cors

在设计器中打开 ↗

写入 CORS 响应头

使用说明

要点:把 CORS 响应头写入消息 Header,适合纯流程提供跨域接口时使用。credentials=true 时 origin 不能为 *。

属性

字段类型必填默认值说明
origin
允许来源
文本 可选 *
methods
允许方法
文本 可选 GET,POST,PUT,DELETE,OPTIONS
headers
允许 Header
文本 可选 Content-Type,Authorization,X-Flow-Token
credentials
允许凭证
布尔 可选 true
maxAge
预检缓存(秒)
数字 可选 3600

示例流程

可直接保存为 demo-cors.json 并部署;非入口节点默认套了一个 REST 入口。

Flow JSON
{
  "id": "demo-cors",
  "desc": "CORS 响应头 示例",
  "group": "示例/存储与消息",
  "schemaVersion": 1,
  "nodes": [
    {
      "id": "n1",
      "type": "rest",
      "props": {
        "method": "POST",
        "path": "/demo/cors",
        "desc": "示例入口"
      }
    },
    {
      "type": "cors",
      "props": {
        "origin": "https://example.com",
        "methods": "GET,POST,OPTIONS",
        "headers": "Content-Type,Authorization",
        "credentials": true,
        "maxAge": 3600
      },
      "id": "n1"
    }
  ]
}
部署这段流程
curl -X POST 'http://localhost:8086/flow' \
  -H 'Content-Type: application/json' \
  -H 'X-Flow-Token: change-me' \
  --data-binary @demo-cors.json

调用方式

如何触发:示例使用 REST 入口,部署后调用 POST http://localhost:8086/demo/cors。

相关节点