0

枪 0.8.8,Node.js 到 Node.js,Node.js 到浏览器

我在浏览器控制台中看到以下错误:

VM103:161 WebSocket connection to 'wss://127.0.0.1:8080/gun' failed: Error in connection establishment: net::ERR_INSECURE_RESPONSE
VM103:161 WebSocket connection to 'wss://10.42.0.56:8080/gun' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

Node.js 端没有消息。

我的服务器的源代码:

const Hapi = require('hapi');
const Gun = require('gun');
const pem = require('pem');

pem.createCertificate({ days: 1, selfSigned: true }, function (err, keys) {
  if (err) {
    throw err
  }
  const server = new Hapi.Server;

  var tls = {
    key: keys.serviceKey,
    cert: keys.certificate
  };

  server.connection({
    port: 8080,
    tls
  });

  server.connections.forEach(c => Gun({ web: c.listener, file: 'data.json' }));

  server.route({
    method: 'GET',
    path: '/',
    handler: function (request, reply) {
      reply('Server works!');
    }
  });

  server.start();
})
4

1 回答 1

1

为了gun使用自签名证书,您需要两件事:

  1. 午餐浏览器忽略证书错误。例如,铬

    google-chrome --ignore-certificate-errors

  2. 将以下进程选项放入 Node.js 代码中

    process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

    或者添加环境变量

    export NODE_TLS_REJECT_UNAUTHORIZED=0

于 2017-10-26T08:40:34.433 回答