【发布时间】:2018-04-06 16:54:37
【问题描述】:
我的 web 应用程序有一个 websocket 服务器,网址为:http://example.com:8080,当我在服务器上运行它时,它适用于我的域 http://anotherdomain.com,但它也适用于其他域 http://baddomain.com 我想要的是阻止其他域访问我的 websocket,即我希望只有我的域可以访问我的 websocket 我该怎么办?
我正在使用 nodejs 的 ws 模块 (https://github.com/websockets/ws)
const WebSocket = require('ws')
const wss = new WebSocket.Server({port:8080})
wss.on('connection', ws => {
ws.on('message', data => {
// something here
})
})
【问题讨论】: