{"id":7802,"date":"2015-10-27T09:45:40","date_gmt":"2015-10-27T09:45:40","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/10\/27\/rxjs-node-js-http-server-implementation-open-source-projects-reactive-extensions-rxjs\/"},"modified":"2015-10-27T09:45:40","modified_gmt":"2015-10-27T09:45:40","slug":"rxjs-node-js-http-server-implementation-open-source-projects-reactive-extensions-rxjs","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/10\/27\/rxjs-node-js-http-server-implementation-open-source-projects-reactive-extensions-rxjs\/","title":{"rendered":"RxJS + node.js HTTP server implementation?-open source projects Reactive-Extensions\/RxJS"},"content":{"rendered":"<p>I &#8216;ve been well with node.js until RxJS implementation.<\/p>\n<p>Here is my trial code studying-<\/p>\n<p><strong>Reactive-Extensions \/ rxjs-node https:\/\/github.com\/Reactive-Extensions\/rxjs-node<\/strong><\/p>\n<p>rx_http.js<br \/>\n(RxJS wrapper of the http lib of node.js)<\/p>\n<pre><code>var Rx = require(\".\/rx.min\");\nvar http = require(\"http\");\nfor(var k in http)\n{\n    exports[k] = http[k];\n}\nexports.createServer = function ()\n{\n    var subject = new Rx.AsyncSubject();\n    var observable = subject.asObservable();\n    observable.server = http.createServer(function (request, response)\n    {\n       subject.onNext({ request:request, response:response });\n       subject.onCompleted();\n    });\n    return observable;\n};\n<\/code><\/pre>\n<p>server.js<\/p>\n<pre><code>var http = require('.\/rx_http');\n\n\/\/ rxServer\nvar serverObservable = http.createServer();\nvar port = 3000;\nserverObservable.server.listen(port);\nconsole.log(\"Server listening on port: \"+port);\n\n\/\/ HTTP request event loop function\nserverObservable.subscribe(function (data)\n{\n    var req = data.request;\n    console.log(req.headers);\n\n    var res = data.response;\n    res.writeHead(200, {'Content-Type':\"text\/html\"});\n    res.end(\"hello world\");\n\n    console.log(\"res content out\");\n});\n\n\/\/ exceptiopn\nprocess.on('uncaughtException', function (err)\n{\n    console.log(['Caught exception:', err.message].join(\" \"));\n});\n<\/code><\/pre>\n<p>The code ends up with one-time &#8216;hello world&#8217; output to browser, and the RxServer stops reacting to another access (brwoser reload etc.).<\/p>\n<p>I&#8217;m on the way to learn RxJS thing, but few documentation found on the web.<\/p>\n<p>Tell me what&#8217;s wrong with the code, and if you know better implementations, please share. Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I &#8216;ve been well with node.js until RxJS implementation. Here is my trial code studying- Reactive-Extensions \/ rxjs-node https:\/\/github.com\/Reactive-Extensions\/rxjs-node rx_http.js (RxJS wrapper of the http lib of node.js) var Rx = require(&#8220;.\/rx.min&#8221;); var http = require(&#8220;http&#8221;); for(var k in http) { exports[k] = http[k]; } exports.createServer = function () { var subject = new Rx.AsyncSubject(); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7802","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7802"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7802\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}