我使用Pusher在Nodejs中启动实时。但是我在编码时遇到了一个问题。这是我的问题。
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^
Error
at new RequestError (C:\Users\Admin\Documents\GitHub\Project\Book-Social-Network\backend\node_modules\pusher\lib\errors.js:13:16)
at C:\Users\Admin\Documents\GitHub\Project\Book-Social-Network\backend\node_modules\pusher\lib\requests.js:74:13
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
name: 'PusherRequestError',
message: 'Request failed with an error',
url: 'https://api-book-social.pusher.com/apps/1566147/events?auth_key=8856b27e23cd9a64d102&auth_timestamp=1679061377&auth_version=1.0&body_md5=4ee5707c207779744a1024fce29c74ce&auth_signature=c6363acc371e84e29d21b54db2a367dd3d3510cb986710a90c7c855c259d0854',
error: FetchError: request to https://api-book-social.pusher.com/apps/1566147/events?auth_key=8856b27e23cd9a64d102&auth_timestamp=1679061377&auth_version=1.0&body_md5=4ee5707c207779744a1024fce29c74ce&auth_signature=c6363acc371e84e29d21b54db2a367dd3d3510cb986710a90c7c855c259d0854 failed, reason: getaddrinfo ENOTFOUND api-book-social.pusher.com
at ClientRequest.<anonymous> (C:\Users\Admin\Documents\GitHub\Project\Book-Social-Network\backend\node_modules\node-fetch\lib\index.js:1505:11)
at ClientRequest.emit (node:events:513:28)
at TLSSocket.socketErrorListener (node:_http_client:481:9)
at TLSSocket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
type: 'system',
errno: 'ENOTFOUND',
code: 'ENOTFOUND'
},
status: undefined,
body: undefined
}
Node.js v18.6.0
[nodemon] app crashed - waiting for file changes before starting...
这是我的代码:
const pusher = new Pusher({
appId: process.env.PUSHER_APPID,
key: process.env.PUSHER_KEY,
secret: process.env.PUSHER_SECRET,
cluster: process.env.PUSHER_CLUSTER,
useTLS: true,
});
const db = mongoose.connection;
db.once('open', () => {
const msgCollection = db.collection('chats');
const msgChangeStream = msgCollection.watch();
msgChangeStream.on('change', (change) => {
if (change.operationType === 'insert') {
const messageDetails = change.fullDocument;
pusher.trigger('messages', 'insert', {
content: messageDetails.content,
users: messageDetails.users,
sender: messageDetails.sender,
});
} else {
console.log('Error Trigger Pusher');
}
});
这是文档:https://pusher.com/tutorials/mongodb-change-streams/#configuring-mongodb
1条答案
按热度按时间vltsax251#
您的系统连接到的集群是
book-social
-它不是推送器集群(https://pusher.com/docs/channels/miscellaneous/clusters/#what-clusters-exist?)。您应确保根据推送器控制面板正确指定您的凭据。