我无法连接到localhost上的wss。我有以下设置:
我使用
创建了证书openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365
我启动了一个wss服务器
const server = https.createServer({
cert: fs.readFileSync('./cert.pem'),
key: fs.readFileSync('./key.pem'),
passphrase: 'ledtesting'
});
const wss = new WebSocket.Server({ server });
server.listen(8000, 'localhost',function listening () {
console.log(server.address().port);
const ws = new WebSocket(`wss://localhost:${server.address().port}`, {
rejectUnauthorized: false
});
});
我正在运行一个电子应用程序,并使用以下网址连接到此Web套接字服务器:
var localsockUrl = "wss://localhost:8000/";
var localsocket = new WebSocket(localsockUrl);
我收到以下错误:
connection to 'wss://localhost:8000/' failed: WebSocket opening handshake was canceled
如何在电子应用上访问localhost上的wss?
答案 0 :(得分:1)
在电子应用设置中,您可以通过以下方式忽略证书错误:
app.commandLine.appendSwitch("ignore-certificate-errors");