不建议使用“加密”选项,而推荐使用“ useTLS”

时间:2019-02-09 15:10:48

标签: node.js

我尝试通过命令行节点server.js运行我的server.js文件,但是我收到此错误消息,但无法解决它,我使用了谷歌浏览器,我修改了设置tq我停用了parmae​​tree TLS1 .0,但是如果没有verro,有人可以帮忙吗?谢谢

server.js

require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const Pusher = require('pusher');

const Sentiment = require('sentiment');
const sentiment = new Sentiment();

const pusher = new Pusher({
  appId: process.env.PUSHER_APP_ID,
  key: process.env.PUSHER_KEY,
  secret: process.env.PUSHER_SECRET,
  cluster: process.env.PUSHER_CLUSTER,
  encrypted: true,
});
const app = express();
const port = process.env.PORT || 4000;

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use((req, res, next) => {
  res.header('Access-Control-Allow-Origin', '*');
  res.header(
    'Access-Control-Allow-Headers',
    'Origin, X-Requested-With, Content-Type, Accept'
  );
  next();
});

app.listen(port, () => {
  console.log(`Server started on port ${port}`);
});
app.post('/messages', (req, res) => {
    const { body } = req;
    const { text, id } = body;
    const result = sentiment.analyze(text);
    const comparative = result.comparative;
    const tone =
      comparative >= 0 ? (comparative >= 1 ? 'positive' : 'neutral') : 'negative';
    const data = {
      text,
      id,
      timeStamp: new Date(),
      sentiment: {
        tone,
        score: result.score,
      },
    };
    pusher.trigger('chat', 'message', data);
    res.json(data);
  });

1 个答案:

答案 0 :(得分:2)

这意味着'encrypted'关键字已被弃用,您将必须使用如下所示的'useTLS':

const pusher = new Pusher({
  appId: process.env.PUSHER_APP_ID,
  key: process.env.PUSHER_KEY,
  secret: process.env.PUSHER_SECRET,
  cluster: process.env.PUSHER_CLUSTER,
  useTLS: true,
});