无法使用http节点代理

时间:2016-12-22 10:04:04

标签: node.js socket.io

我正在服务器上部署我的node.js聊天服务器。现在在服务器上,Https在端口8443上启用,我的服务器在端口3000上运行。现在每当我在服务器上部署我的node.js express服务器时它就开始监听但每当我尝试在浏览器中打开页面时#34; Segmentation Fault"写在我的专用服务器控制台上。我已经仔细检查了我的证书他们没问题任何人都可以在这里指导我,导致问题的原因是什么?是与端口相关的问题还是与代码相关的问题?

    // Setup basic express server
var express = require('express');
var app = express();
var fs = require('fs');
var httpProxy=require('http-proxy');
var proxy = httpProxy.createProxyServer({});

var options = {
  key: fs.readFileSync('/etc/pki/tls/private/demo.iproctoring.com.key'),
  cert: fs.readFileSync('/etc/pki/tls/certs/demo.iproctoring.com.cer')
};
var server = require('https').createServer(options,app,function(req,res)
{
proxy.web(req, res, { target: 'https://demo.iproctoring.com:8443' });
});
var io = require('../..')(server);
var port = process.env.PORT || 3000;

server.listen(port, function () {
  console.log('Server listening at port %d', port);
});

app.use(express.static(__dirname + '/public'));


var numUsers = 0;

io.on('connection', function (socket) {
  var addedUser = false;

  // when the client emits 'new message', this listens and executes
  socket.on('new message', function (data) {
    // we tell the client to execute 'new message'
    socket.broadcast.emit('new message', {
      username: socket.username,
      message: data
    });
  });

  // when the client emits 'add user', this listens and executes
  socket.on('add user', function (username) {
    if (addedUser) return;

    // we store the username in the socket session for this client
    socket.username = username;
    ++numUsers;
    addedUser = true;
    socket.emit('login', {
      numUsers: numUsers
    });
    // echo globally (all clients) that a person has connected
    socket.broadcast.emit('user joined', {
      username: socket.username,
      numUsers: numUsers
    });
  });

  // when the client emits 'typing', we broadcast it to others
  socket.on('typing', function () {
    socket.broadcast.emit('typing', {
      username: socket.username
    });
  });

  // when the client emits 'stop typing', we broadcast it to others
  socket.on('stop typing', function () {
    socket.broadcast.emit('stop typing', {
      username: socket.username
    });
  });

  // when the user disconnects.. perform this
  socket.on('disconnect', function () {
    if (addedUser) {
      --numUsers;

      // echo globally that this client has left
      socket.broadcast.emit('user left', {
        username: socket.username,
        numUsers: numUsers
      });
    }
  });
});

0 个答案:

没有答案