Reputation: 61
I have installed all extensions, client closed error persists
const faye = require('faye');
const express = require('express');
const http = require('http');
const app = express();
const router = express.Router();
var bodyParser = require('body-parser');
const path = require('path');
const fayeRedis = require('faye-redis');
app.use(bodyParser.json())
var shards = [
{
shardName: 'redis-1', // unique shard name used for consistent hashing -- if not supplied, will default to "host + ':' + port"
host: 'localhost', // required
port: 6379 // requiredrue
}
];
var bayeux = new faye.NodeAdapter({
mount: '/faye',
engine: {
type: fayeRedis,
shards: shards
},
ping: 2,
timeout: 20
})
app.use(express.static("public"));
app.use(bodyParser.urlencoded({
limit: "10mb",
extended: true
}));
var channel='/channel'
app.use('', router);
const server = http.createServer(app);
bayeux.attach(server);
server.listen(8082);
router.post('/message', function(req,res){
try {
bayeux.getClient().publish('/channel',"hello");
} catch (err) {
console.error("we got exception", err);
}
console.log("published message");
res.sendStatus(200);
});
router.get("/client",(req,res) =>{
res.sendFile(path.join(__dirname+'/client.html'))
})
router.get('/health', (req, res) => {
console.log("getting response");
res.sendStatus(200);
});
console.log("hello world!");
the debug screen
hello world! /Users/prashant/Downloads/node_modules/@redis/client/dist/lib/client/index.js:409 return Promise.reject(new errors_1.ClientClosedError()); ^
ClientClosedError: The client is closed at Commander._RedisClient_sendCommand (/Users/prashant/Downloads/node_modules/@redis/client/dist/lib/client/index.js:409:31) at Commander.SELECT (/Users/prashant/Downloads/node_modules/@redis/client/dist/lib/client/index.js:209:99) at new Engine (/Users/prashant/Downloads/node_modules/faye-redis/faye-redis.js:27:15) at Function.Engine.create (/Users/prashant/Downloads/node_modules/faye-redis/faye-redis.js:45:10) at klass.initialize (/Users/prashant/Downloads/node_modules/faye/src/engines/proxy.js:26:35) at new klass (/Users/prashant/Downloads/node_modules/faye/src/util/class.js:13:28) at Function.get (/Users/prashant/Downloads/node_modules/faye/src/engines/proxy.js:111:12) at klass.initialize (/Users/prashant/Downloads/node_modules/faye/src/protocol/server.js:20:29) at new klass (/Users/prashant/Downloads/node_modules/faye/src/util/class.js:13:28) at Function.Server.create
I have tried searching in other forums, couldn't find a proper solution. Thanks in advance for the solution
Upvotes: 2
Views: 121