在Hapi服务器中使用TLS时出现套接字挂起

时间:2017-09-30 02:07:24

标签: node.js ssl hapijs

每当服务器启动时,我都会看到以下控制台错误消息:

Server started at: https://localhost:3333
170929/232536.579, [log,connection,client,error] message: socket hang up, stack: Error: socket hang up
    at TLSSocket.<anonymous> (_tls_wrap.js:829:25)
    at emitOne (events.js:95:20)
    at TLSSocket.emit (events.js:182:7)
    at Socket.<anonymous> (net.js:484:12)
    at Socket.g (events.js:273:16)
    at emitOne (events.js:90:13)
    at Socket.emit (events.js:182:7)
    at TCP._onclose (net.js:484:12)

我能够确定,如果我从server.connection中删除了tls选项,则错误消失。

这是服务器中的代码

import Hapi from 'hapi';
import inert from 'inert';
import fs from 'fs';
import { apiRoutes } from './api/api-routes';
import { serverConfig } from 'common';
import _ from 'lodash';

const good = require('good');
const server = new Hapi.Server();

const tls = {
  key: fs.readFileSync('cert/server-key.pem'),
  cert: fs.readFileSync('cert/server-crt.pem'),
  ca: fs.readFileSync('cert/ca-crt.pem'),
};

const host = serverConfig.host;
const port = serverConfig.port; 

server.connection({
  address: '0.0.0.0', // listen on all interfaces!
  host,
  port,
  tls,
});

const options = {
  reporters: {
    myConsoleReporter: [{
      module: 'good-squeeze',
      name: 'Squeeze',
      args: [{ log: '*', response: '*' }],
    }, {
      module: 'good-console',
    }, 'stdout'],
myFileReporter: [{
  module: 'good-squeeze',
  name: 'Squeeze',
  args: [{ ops: '*' }],
    }, {
      module: 'good-squeeze',
      name: 'SafeJson',
    }, {
      module: 'good-file',
      args: ['./hapi.log'],
    }],
  },
};

server.register([
  {
    register: inert,
  },
  {
    register: good,
    options,
  },
],
(err) => {
   if (err) {
   throw 

// define static ui
server.route({
  method: 'GET',
  path: '/{path*}',
  handler: {
    directory: {
      path: serverConfig.staticAssetsDir,
    },
  },
});

    // start server
    server.start(() => {
        console.log(`Server started at: ${server.info.uri}`);
    });
  }
);

可能是什么问题,我怎么能开始调试呢?

0 个答案:

没有答案