[GO]解决request origin not allowed by Upgrader.CheckOrigin websocket跨域

在gin框架下使用websocket , 如果是跨域请求的时候会报这个错误

request origin not allowed by Upgrader.CheckOrigin

 

使用的websocket库是 "github.com/gorilla/websocket"

需要增加以下代码:

    upgrader = websocket.Upgrader{
        ReadBufferSize:  1024,
        WriteBufferSize: 1024,
        // 解决跨域问题
        CheckOrigin: func(r *http.Request) bool {
            return true
        },
    }

 

[GO]解决request origin not allowed by Upgrader.CheckOrigin websocket跨域

上一篇:原生js实现 正方体旋转


下一篇:MongoDb集群部署