Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var hello_ruby = require('./hello_ruby');
- var ruby = hello_ruby.ruby;
- ruby.define_class('NodeJSResponse');
- ruby.define_method(ruby.c.NodeJSResponse, 'writeHead', 2, function(self, status, headers) {
- status = this.check_convert_type(status, this.c.Fixnum, 'to_i');
- headers = this.check_convert_type(headers, this.c.Hash, 'to_hash');
- var node_headers = {};
- var iterator = function(self, args) {
- var name = this.check_convert_type(args[0], this.c.String, 'to_s');
- var value = this.check_convert_type(args[1], this.c.String, 'to_s');
- node_headers[name] = value;
- };
- this.funcall2(headers, 'each', [], this.lambda(iterator));
- self.internal.writeHead(status, node_headers);
- });
- ruby.define_method(ruby.c.NodeJSResponse, 'write', 1, function(self, data) {
- data = this.check_convert_type(data, this.c.String, 'to_s');
- self.internal.write(data);
- });
- ruby.define_method(ruby.c.NodeJSResponse, 'end', 0, function(self) {
- self.internal.end();
- });
- var http = require('http');
- http.createServer(function (req, res) {
- var ruby_res = {
- klass: ruby.c.NodeJSResponse,
- internal: res,
- };
- ruby.protect(function() {
- var reply = ruby.funcall(ruby.toplevel, 'process_request', ruby_res);
- }, function(e) {
- console.log("Exception Occured: " + ruby.funcall(e, 'to_s'));
- });
- }).listen(1337, "127.0.0.1");
- console.log('Server running at http://127.0.0.1:1337/');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement