Last active
May 30, 2017 17:34
-
-
Save fkchang/b5e0808c7b74161ff729d5f25fce6660 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
require 'nodejs' | |
require 'native' | |
module HTTP | |
HTTP_JS = Native(node_require('http')) | |
class Server | |
def self.listen(port, &block) | |
HTTP_JS.createServer(lambda { |req_js, res_js| | |
block.call(Native(req_js), Native(res_js)) | |
}).listen(port) | |
end | |
end | |
end | |
port = 1337 | |
HTTP::Server.listen(port) { |req, res| | |
res.writeHead(200, {'Content-Type': 'text/plain'}.to_n ) | |
res.end "Hello World\n" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment