javascript - Why do I get a Bad request when I run server.js and client.js and access localhost? -
i new node.js
i trying utilize pub/sub faye nodemodule create publish/subscribe web application.
i have next files , folders: dependencies in node_modules folder, sever.js file, , client.js
my server.js contains next code:
var http = require('http'), faye = require('faye'); var server = http.createserver(), bayeux = new faye.nodeadapter({mount: '/'}); bayeux.attach(server); server.listen(8000);
as client.js file, contains next code:
var faye = require('faye') var client = new faye.client('http://localhost:8000/'); client.subscribe('/messages', function(message) { alert('got message: ' + message.text); }); client.publish('/messages', { text: 'hai!' })
i go terminal , run node server.js , node client.js
when go browser , run localhost:8000, bad request.
why getting this? suspecting don't have page display something. please point out me missing.
thanks.
you're getting error because you've mounted faye @ /
. if seek browsing /
, server expecting faye client, not normal http request.
there browser client example shows how connect faye mounted @ /faye
. can pass in request
handler http.createserver()
allows handle request before faye does, in case want respond particular request.
javascript node.js faye
No comments:
Post a Comment