存储与消息
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 入口。
{
"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。