Closed ccoenraets closed 7 years ago
The module does have an adapt()
function (https://github.com/cometd/cometd-nodejs-client/blob/master/cometd-nodejs-client.js#L2) and you must call it to have the module work properly.
The version installed via npm (1.0.0-BETA0) does not have an adapt() function. Will try with the version from the repo. Thanks.
Install latest version on tag beta
.
OK, got 1.0.0-BETA3 with adapt() function. I'm still getting ReferenceError: XMLHttpRequest is not defined
. I'm patching it with global.XMLHttpRequest = window.XMLHttpRequest;
in my module, but then getting Error: Protocol "https:" not supported. Expected "http:"
. Thanks.
Install cometd
at tag beta
as well. Sorry, stuff is still experimental :)
No problem. Appreciate the hard work on the library. The beta of cometd fixed the first problem (XMLHttpRequest is not defined), but it looks like the adapter does not support https. Still getting Protocol "https:" not supported. Expected "http:"
.
Quick fix to make it work in my specific use case. require('https'), and add Content-Length header: _config.headers['Content-Length'] = JSON.stringify(data).length;
.
Can you please detail how you get the "https:" not supported. Expected "http:"
error ?
I think I understand the https
error now... I guess you're using https:
URLs, but in the code I only use the http
module to send requests, while I should switch using either the http
module or the https
module depending on the URL scheme.
The suggestion you made about the Content-Length
header is not correct since the length of the string is not equal to the length in bytes in case of non-ASCII characters.
@ccoenraets I filed #6 to isolate the https
issue.
Can you please try the latest code (from HEAD, copy and paste the new code - it's not published to NPM yet) and report if it works for you ?
A possible suggestion for this https
issue, is option to pass in an Agent object. Then no effort to decide inside cometd-nodes-client. Similar to the way Request module options work. The caller decides the many possible configurations of the http agent. Plus then will be able to instantiate many cometd clients per process with unique sandboxed agent objects. Also important, just like Request, allow optional Cookie store to be passed in.
I can separate my comments into Agent for issue #6, and another for Cookies.
Request modules optional options:
@glennschler, the goal of this library is not to be a full rewrite of the browser CometD client, but just perform the necessary adaptations to make it work in a NodeJS environment. It basically has to just "fake" XMLHttpRequest
.
From fixing #6, passing an Agent
is not enough, since you have to switch on the http
and https
modules as well.
Cookies have been solved in #4.
require('cometd-nodejs-client').adapt()
, but the module doesn't have an adapt() function.require('cometd-nodejs-client')
, but then ran into an 'XMLHttpRequest is not defined' errorglobal.XMLHttpRequest = window.XMLHttpRequest;
in my module, but then ran in 'https not supported' errorvar http = require('http');
withvar http = require('https');
in cometd-nodejs-client.js but now running in 'Length Required' error.Am I using this right or is there another way to use this module? Thanks