Created
June 1, 2010 01:19
-
-
Save probablycorey/420448 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Try loading these three urls | |
| // [1] http://localhost:8080/goog | |
| // [2] http://localhost:8080/google | |
| // [3] http://localhost:8080/goog | |
| // | |
| // The 1 & 2 will load when the google_emitter is called, 3 doesn't but gets called on | |
| // the next update | |
| var sys = require("sys"), | |
| url = require("url"), | |
| events = require("events"); | |
| var emitter = new events.EventEmitter(); | |
| function get_body() { | |
| emitter.emit("body", "Look, here is your data!"); | |
| } | |
| setInterval(get_body, 10000); | |
| http.createServer(function(request, response) { | |
| var uri = url.parse(request.url).pathname; | |
| if (uri.match(/goog/i)) { | |
| var listener = emitter.addListener("body", function(body) { | |
| response.sendHeader(200, { "Content-Type" : "text/plain" }); | |
| response.write(body); | |
| response.close(); | |
| }); | |
| } | |
| }).listen(8080); | |
| sys.puts("Server running at http://localhost:8080/"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment