I have a bit of an issue. I'm trying to create a dynamic web app using node.js/express.js/now.js. I've done everything as shown in the small sample code at http://nowjs.com/download , with no success, the client-side now.js script hosted properly, but now.ready(..) never fires. The only differences are that I use express and my server which is used to initialze now.js is https.
Do you have any ideas which could cause it not to work?
server side:
var server = express.createServer(..);
..
server.listen(port, function() {..});
var nowjs = require('now');
var everyone = nowjs.initialize(server);
everyone.now.log = function(msg) { console.log(msg); }
client side:
<script type="text/javascript" src="/nowjs/now.js"></script>
<script type="text/javascript">
now.ready(function() { now.log('asd'); alert('asd'); });
</script>
Any help would be highly appreciated!
Best, Kornel
Well, found the answer. Long answer: now.js has an issue when determining the communication port on which socket.io should communicate. This issue seems only to appear when using default https port (443).
I've found two solutions, the ugly one: https://groups.google.com/forum/?fromgroups=#!topic/nowjs/8cO9D77tN2o
Basically you need to edit the source code of now.js at now/lib/fileServer.js and replace
var hostPort = options['port'] || host[1] || '80';
with
var hostPort = options['port'] || host[1] || ((request.headers.referer.split(':')[0] === 'https') ? '443' : '80');
The nicer one is to set port options to socket.io. Lucky us, this is supported by now.js:
var everyone = nowjs.initialize(server, {port: port, socketio: {transports: ['xhr-polling', 'jsonp-polling']}});
I hope that this will help others having the same issue and also hope that this behavior will be fixed later in now.js.
Best regards: Kornel