How to code simple subscriber/publisher for HTTPS

24 views
Skip to first unread message

Laeeq Khan

unread,
Aug 2, 2019, 2:03:57 PM8/2/19
to Faye users
I am trying to make a simple Bayeux publis her/subscriber system working on HTTPS, not HTTP.  Server comes up without error, but both subscriber and publisher return "trasport:down" 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



consolidated_https_faye.txt
Reply all
Reply to author
Forward
0 new messages