coze-dev / coze-dev/coze-studio

chat web sdk集成出现跨域问题:has been blocked by CORS policy

Open
#622 1 comment 0 reactions 0 assignees View on GitHub
frontend
Dominant language
TypeScript
Stars
21.6k
Forks
3.1k
PR merge metrics
No merged PRs in 30d

Description

Access to XMLHttpRequest at 'http://192.168.0.201:8888/v1/conversations?bot_id=7534995494469107712&connector_id=999&page_num=1&page_size=1' from origin 'http://192.168.0.158:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
@coze_chat-sdk_webJs.js?v=cdeae98f:4668 [coze-mini-sdk] [error] Get Message Error TypeError: Cannot read properties of undefined (reading 'content-type')
at MiniCozeApi._callee56$ (@coze_chat-sdk_webJs.js?v=cdeae98f:8039:329)
at tryCatch (@coze_chat-sdk_webJs.js?v=cdeae98f:1347:54)
at Generator. (@coze_chat-sdk_webJs.js?v=cdeae98f:1424:28)
at Generator.next (@coze_chat-sdk_webJs.js?v=cdeae98f:1370:31)
at asyncGeneratorStep (@coze_chat-sdk_webJs.js?v=cdeae98f:1563:30)
at _next (@coze_chat-sdk_webJs.js?v=cdeae98f:1575:19)

error @ @coze_chat-sdk_webJs.js?v=cdeae98f:4668
@coze_chat-sdk_webJs.js?v=cdeae98f:4668 [coze-mini-sdk] [error] get chat info error MiniChatError: Cannot read properties of undefined (reading 'content-type')
at _callee2$ (@coze_chat-sdk_webJs.js?v=cdeae98f:16443:116)
at tryCatch (@coze_chat-sdk_webJs.js?v=cdeae98f:1347:54)
at Generator. (@coze_chat-sdk_webJs.js?v=cdeae98f:1424:28)
at Generator.throw (@coze_chat-sdk_webJs.js?v=cdeae98f:1370:31)
at asyncGeneratorStep (@coze_chat-sdk_webJs.js?v=cdeae98f:1563:30)
at _throw (@coze_chat-sdk_webJs.js?v=cdeae98f:1578:19)

在同一个局域网不同ip部署的,出现上述问题:
根据https://github.com/hertz-contrib/cors,我看到运行所有域名是这个配置:
func main() {
h := server.Default()
// same as
// config := cors.DefaultConfig()
// config.AllowAllOrigins = true
// h.Use(cors.New(config))
h.Use(cors.Default())
h.Spin()
}
通配符 * 可能当字符串处理了。不知道是不是这个问题?

Contributor guide

Open the contributing guide

Research direction

Reproduce the preflight request from http://192.168.0.158:3000 to the /v1/conversations endpoint and inspect the server's CORS middleware configuration, starting with the hertz-contrib/cors setup shown in the issue. Check the MiniCozeApi request path in coze_chat-sdk_webJs.js and verify that the response includes the required CORS headers; done means the request succeeds across the two LAN origins without the SDK errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, typescript
Domain
api, backend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.