Skip to content

Instantly share code, notes, and snippets.

@fkchang
Last active May 30, 2017 17:34
Show Gist options
  • Save fkchang/b5e0808c7b74161ff729d5f25fce6660 to your computer and use it in GitHub Desktop.
Save fkchang/b5e0808c7b74161ff729d5f25fce6660 to your computer and use it in GitHub Desktop.
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