I am trying to make a simple Bayeux publis her/subscriber system working on HTTPS,
error. Please see the code below and let me know what I am doing wrong. Thanks very much.
-------- Faye HTTPS server -- index.js -------
const https = require('https');
const fs = require('fs');
function requestHandler(req, res){
console.log('request url = ', req.url);
if(req.url == '/'){
res.end('Home Page - 201');
} else if(req.url == '/aaa'){
res.end('AAA');
} else if(req.url == '/bbb'){
res.end('BBB');
} else{
res.end('Cant fullfill this request');
}
}
serverOptions = {
key : fs.readFileSync('./key.pem'),
cert : fs.readFileSync('./cert.pem'),
passphrase : '1234'
}
const httpsServer = https.createServer(serverOptions, requestHandler);
httpsServer.listen(7000);
-------- Faye HTTPS subscriber --- subscriber.js ------
faye = require('faye');
function msgReceived(msg){
console.log('Msg received');
console.log(msg.text);
}
function srvrNotRdy(){
console.log('===> Server is not ready');
}
const recvClient = new faye.Client('https://localhost:7000');
recvClient.bind('transport:down', srvrNotRdy);
recvClient.subscribe('/messages', msgReceived);
console.log('--- subscription complete ---');
-------- Faye HTTPS publisher --- publisher.js ------
const faye = require('faye');
function srvrNotRdy(){
console.log('====> Server is not ready ...');
}
const publisherClient = new faye.Client('https://localhost:7000');
publisherClient.bind('transport:down', srvrNotRdy);
console.log('Going to publish message');
publisherClient.publish('/messages',{text : 'Test message - 7'});
console.log('Message published ...');
-------- Invocation results ---------
Server runs fine:
node index.js
Running subscriber returns 'transport:down' error
node subscriber.js
--- subscription complete ---
===> Server is not ready
Running publisher returns 'transport:down' error
node publisher.js
Going to publish message
Message published ...
====> Server is not ready ...
Bad request