Created
September 2, 2012 15:54
-
-
Save pyykkis/3600830 to your computer and use it in GitHub Desktop.
Node.js httpServer middleware as it should be
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
curl localhost:3000 |
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
DEBUG: Starting child process with 'coffee server.coffee' | |
BAR 127.0.0.1 -- [Sun Sep 02 2012 20:31:09 GMT+0300 (EEST)] GET / HTTP/1.1 | |
FOO 127.0.0.1 -- [Sun Sep 02 2012 20:31:09 GMT+0300 (EEST)] GET / HTTP/1.1 |
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
http = require 'http' | |
useRequestLogger = (handler, name) -> | |
(req, res) -> | |
console.log name, req.connection.remoteAddress, "--", "[#{new Date}]", req.method, req.url, "HTTP/#{req.httpVersion}" | |
handler req, res | |
app = (req, res) -> | |
setTimeout (-> res.end "World!\n"), 1000 | |
setTimeout (-> res.write "Hello, "), 500 | |
app = useRequestLogger app, "FOO" | |
app = useRequestLogger app, "BAR" | |
server = http.createServer app | |
server.listen 3000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment