Advertisement
Guest User

Untitled

a guest
Jul 9th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var sha1 = require("./sha1").hex;
  2. var http = require("http");
  3. var mysql = require('./mysql');
  4. var settings = require("./settings");
  5.  
  6. if(Array.prototype.clear === undefined)
  7. Array.prototype.clear = function()
  8. {
  9.     for(var i=this.length; i>=0; i--)
  10.         delete this[i];
  11.     this.length = 0;
  12.     return this;
  13. }
  14.  
  15. if(Array.prototype.contains === undefined)
  16. Array.prototype.contains = function(element)
  17. {
  18.     return this.indexOf(element)!=-1;
  19. }
  20.  
  21. if(Array.prototype.add === undefined)
  22. Array.prototype.add = function(element)
  23. {
  24.     if(!this.contains(element))
  25.         this.push(element);
  26. }
  27.  
  28. if(Array.prototype.remove === undefined)
  29. Array.prototype.remove = function(value)
  30. {
  31.  
  32.     for(var i=0; i<this.length; i++)
  33.         if(this[i] === value)
  34.             this.splice(i--, 1);
  35.     return this;
  36. }
  37.  
  38. if(Array.prototype.clean === undefined)
  39. Array.prototype.clean = function()
  40. {
  41.     for(var i=0; i<this.length; i++)
  42.         if(this[i] === undefined
  43.         || this[i] === null)
  44.             this.splice(i--, 1);
  45.     return this;
  46. }
  47.  
  48. if(Array.prototype.clear === undefined)
  49. Array.prototype.clear = function()
  50. {
  51.     for(var i=this.length; i>=0; i--)
  52.         delete this[i];
  53.     this.length = 0;
  54.     return this;
  55. }
  56.  
  57. function JSONResponse(database, request, response)
  58. {
  59.     var self = this;
  60.  
  61.     this._user = undefined;
  62.     this._database = database;
  63.     this._request = request;
  64.     this._response = response;
  65.     this._JSONObject = {};
  66.     this._time = new Date();
  67.  
  68.     this._cookie = {};
  69.  
  70.     var rawcookie = request.headers.cookie
  71.             ?request.headers.cookie.split(/;\s*/)
  72.             :[];
  73.     for(var i=0; i<rawcookie.length; i++)
  74.     {
  75.         rawcookie[i] = rawcookie[i].split("=");
  76.         this._cookie[rawcookie[i][0]] = unescape(rawcookie[i][1]);
  77.     }
  78.  
  79.     this._params = request.url.substr(1).split("/");
  80.  
  81.     console.log(this._params);
  82.  
  83.     response.writeHead(200,{"Content-Type": "application/json"});
  84.  
  85.     this.getTime = function()
  86.     {
  87.         return self._time;
  88.     }
  89.  
  90.     this.getCookie = function(key)
  91.     {
  92.         return self._cookie[key];
  93.     }
  94.  
  95.     /**
  96.      * Get the currently logged in user. Calls the callback method with the user
  97.      * that is logged in, or with NULL if there is no login.
  98.      * @param cb The callback function.
  99.      */
  100.     this.validateLogin = function(cb)
  101.     {
  102.         if(this._user !== undefined)
  103.         {
  104.             cb(self._user);
  105.             return;
  106.         }
  107.         if(!self.getCookie("login"))
  108.         {
  109.             self._user = null;
  110.             cb(self._user);
  111.             return;
  112.         }
  113.         var loginstr = self.getCookie("login").split(",");
  114.         var userId = parseInt(loginstr[0]);
  115.         var passHash = loginstr[1];
  116.         self._database.getUser(userId, function(user)
  117.         {
  118.             user.checkPassword(passHash, function(isValid)
  119.             {
  120.                 self._user = isValid?user:null;
  121.                 cb(self._user);
  122.             });
  123.         });
  124.     }
  125.  
  126.     this.addError = function(message)
  127.     {
  128.         if(!(self._JSONObject.errors instanceof Array))
  129.             self._JSONObject.errors = new Array();
  130.         self._JSONObject.errors.push(message);
  131.     }
  132.  
  133.     this.getParam = function(i)
  134.     {
  135.         return self._params[i];
  136.     }
  137.  
  138.     this.getParams = function()
  139.     {
  140.         return self._params;
  141.     }
  142.  
  143.     this.getUser = function()
  144.     {
  145.         return self._user;
  146.     }
  147.  
  148.     this.set = function(key, value)
  149.     {
  150.         self._JSONObject[key] = value;
  151.     }
  152.  
  153.     this.get = function(key)
  154.     {
  155.         return self._JSONObject[key];
  156.     }
  157.  
  158.     this.end = function()
  159.     {
  160.         self._response.end(JSON.stringify(self._JSONObject, null, 2));
  161.     }
  162. }
  163.  
  164. function Database(sqlClient)
  165. {
  166.     var self = this;
  167.  
  168.     /** @var The MySQL Client connection. */
  169.     this._sql = sqlClient;
  170.  
  171.     /** @var A cache with Product-objects. */
  172.     this._products = {};
  173.  
  174.     /** @var A cache with User-objects. */
  175.     this._users = {};
  176.  
  177.     /** @var A cache with Bid-objects. */
  178.     this._bids = {};
  179.  
  180.     /** @var A reference to the last bid. */
  181.     this._lastBid = undefined;
  182.  
  183.     this._init = function(cb)
  184.     {
  185.         self.query("SELECT id FROM bids ORDER BY id DESC LIMIT 1",
  186.         [],
  187.         function(results)
  188.         {
  189.             if(!results.length)
  190.             {
  191.                 self._lastBid = null;
  192.                 self._init = undefined;
  193.                 if(cb)cb(self);
  194.                 return;
  195.             }
  196.             self.getBid(results[0].id, function(bid)
  197.             {
  198.                 self._lastBid = bid;
  199.                 self.addOnBidPlacedEventListener(function(bid)
  200.                 {
  201.                     self._lastBid = bid;
  202.                 });
  203.                 self._init = undefined;
  204.                 if(cb)cb(self);
  205.                 return;
  206.             });
  207.         });
  208.     }
  209.  
  210.     /** @var An array with on-bid-placed-event listeners. */
  211.     this._onBidPlacedEventListeners = [];
  212.  
  213.     /**
  214.      *
  215.      */
  216.     this._triggerOnBidPlacedEventListeners = function(bid)
  217.     {
  218.         for(var i=0; i<self._onBidPlacedEventListeners.length; i++)
  219.             self._onBidPlacedEventListeners[i](bid);
  220.     }
  221.  
  222.     /**
  223.      * Add a on-bid-placed-event-listener. The function will be called everytime
  224.      * a bid is placed on any product. The callback will be given a
  225.      * Bid-object which the bid was placed on as a first parameter.
  226.      * @param cb The event-listener.
  227.      */
  228.     this.addOnBidPlacedEventListener = function(cb)
  229.     {
  230.         self._onBidPlacedEventListeners.add(cb);
  231.     }
  232.  
  233.     this.removeOnBidPlacedEventListener = function(cb)
  234.     {
  235.         self._onBidPlacedEventListeners.remove(cb);
  236.     }
  237.  
  238.     this.query = function(sql, params, cb)
  239.     {
  240.         self._sql.query(sql, params, function(err, results)
  241.         {
  242.             if(err)
  243.             {
  244.                 console.log("ERROR EXECUTING QUERY:");
  245.                 console.log(sql);
  246.                 console.log(self._sql);
  247.                 throw err;
  248.             }
  249.             if(cb)cb(results);
  250.         });
  251.     }
  252.  
  253.     this.getLastBid = function()
  254.     {
  255.         return self._lastBid;
  256.     }
  257.  
  258.     this.getProductsStartingBetween = function(start, end, cb)
  259.     {
  260.         self.query("SELECT id FROM products WHERE UNIX_TIMESTAMP(timeStart) "
  261.             +"BETWEEN ? AND ?",
  262.         [start.getTime()/1000, end.getTime()/1000],
  263.         function(results)
  264.         {
  265.             var products = new Array();
  266.             var productsLoadedCallback = function()
  267.             {
  268.                 if(products.length < results.length)
  269.                     return;
  270.                 if(cb)cb(products);
  271.             }
  272.             for(var i=0; i<results.length; i++)
  273.             {
  274.                 self.getProduct(results[i].id, function(product)
  275.                 {
  276.                     products.push(product);
  277.                     productsLoadedCallback();
  278.                 });
  279.             }
  280.         });
  281.     }
  282.  
  283.     this.getLastBidsPlacedAfterBid = function(bid, cb)
  284.     {
  285.         self.query("SELECT id FROM bids WHERE id > ? "
  286.             +"GROUP BY product ORDER BY id",
  287.         [bid?bid.getId():0],
  288.         function(results)
  289.         {
  290.             var bids = new Array();
  291.             var bidsLoadedCallback = function()
  292.             {
  293.                 if(bids.length < results.length)
  294.                     return;
  295.                 if(cb)cb(bids);
  296.             }
  297.             for(var i=0; i<results.length; i++)
  298.             {
  299.                 self.getBid(results[i].id, function(bid)
  300.                 {
  301.                     bids.push(bid);
  302.                     bidsLoadedCallback();
  303.                 });
  304.             }
  305.         });
  306.     }
  307.  
  308.     this.getLastBidsPlacedBetween = function(start, end, cb)
  309.     {
  310.         self.query("SELECT bid.id AS id FROM bids AS bid "
  311.             +"JOIN products AS product ON bid.product = product.id "
  312.             +"WHERE UNIX_TIMESTAMP(product.timeStart)+bid.centiTime/100 "
  313.             +"BETWEEN ? AND ? GROUP BY product.id ORDER BY "
  314.             +"bid.id DESC",
  315.         [start.getTime()/1000, end.getTime()/1000],
  316.         function(results)
  317.         {
  318.             var bids = new Array();
  319.             var bidsLoadedCallback = function()
  320.             {
  321.                 if(bids.length < results.length)
  322.                     return;
  323.                 if(cb)cb(bids);
  324.             }
  325.             for(var i=0; i<results.length; i++)
  326.             {
  327.                 self.getBid(results[i].id, function(bid)
  328.                 {
  329.                     bids.push(bid);
  330.                     bidsLoadedCallback();
  331.                 });
  332.             }
  333.         });
  334.     }
  335.  
  336.     /**
  337.      * Get a product from this database. Calls a callback method with the
  338.      * retrieved Product-object on completion, or with NULL if the Product
  339.      * doesn't exist.
  340.      * @param id The id of the product to get.
  341.      * @param cb The callback.
  342.      */
  343.     this.getProduct = function(id, cb)
  344.     {
  345.         id = parseInt(id);
  346.         if(self._products[id] !== undefined)
  347.         {
  348.             if(cb)cb(self._products[id]);
  349.             return;
  350.         }
  351.         self.query("SELECT title, UNIX_TIMESTAMP(timeStart) AS time, thumbnail,"
  352.                 +"value/100 AS value FROM products WHERE id = ? LIMIT 1",
  353.         [id],
  354.         function(results)
  355.         {
  356.             if(self._products[id])
  357.             {
  358.                 console.log("Tried to reload Product #"+id+".");
  359.                 if(cb)cb(self._products[id]);
  360.                 return;
  361.             }
  362.             if(results.length == 0)
  363.             {
  364.                 console.log("Loaded Product #"+id+": NULL");
  365.                 self._products[id] = null;
  366.                 if(cb)cb(self._products[id]);
  367.                 return;
  368.             }
  369.             self._products[id] = new Product(self, id,
  370.                                              results[0].title,
  371.                                              results[0].thumbnail,
  372.                                              results[0].value,
  373.                                              new Date(results[0].time*1000));
  374.             self._products[id].addOnBidPlacedEventListener(
  375.                     self._triggerOnBidPlacedEventListeners);
  376.             self._products[id]._init(function(product)
  377.             {
  378.                 console.log("Loaded Product #"+id+": "
  379.                     +JSON.stringify(product.getTitle()));
  380.                 if(cb)cb(product);
  381.             });
  382.         });
  383.     }
  384.  
  385.     /**
  386.      * Get a user from this database. Calls a callback method with the retrieved
  387.      * User-object on completion, or with NULL if there is no user with that id.
  388.      * @param id The id of the user.
  389.      * @param cb The callback.
  390.      */
  391.     this.getUser = function(id, cb)
  392.     {
  393.         id = parseInt(id);
  394.         if(self._users[id] !== undefined)
  395.         {
  396.             if(cb)cb(self._users[id]);
  397.             return;
  398.         }
  399.         self.query("SELECT username FROM users WHERE id = ? LIMIT 1",
  400.         [id],
  401.         function(results)
  402.         {
  403.             if(self._users[id])
  404.             {
  405.                 console.log("Tried to reload User #"+id+".");
  406.                 if(cb)cb(self._users[id]);
  407.                 return;
  408.             }
  409.             self._users[id] = results.length == 0
  410.                     ?null
  411.                     :new User(self, id, results[0].username);
  412.             console.log("Loaded User #"+id+": "
  413.                 +(self._users[id]
  414.                     ?JSON.stringify(self._users[id].getUsername())
  415.                     :"NULL"));
  416.             if(cb)cb(self._users[id]);
  417.         });
  418.     }
  419.  
  420.     /**
  421.      * Get a bid from this database. Calls a callback method with the retrieved
  422.      * Bid-object on completion, or with NULL if there is no bid with that id.
  423.      * @param id The id of the bid.
  424.      * @param cb The callback.
  425.      */
  426.     this.getBid = function(id, cb)
  427.     {
  428.         id = parseInt(id);
  429.         if(self._bids[id] !== undefined)
  430.         {
  431.             cb(self._bids[id]);
  432.             return;
  433.         }
  434.         self.query("SELECT id, product, centiTime, user "
  435.                 +"FROM bids WHERE id = ? LIMIT 1",
  436.         [id],
  437.         function(results)
  438.         {
  439.             if(results.length == 0)
  440.             {
  441.                 console.log("Loaded Bid #"+id+": NULL");
  442.                 self._bids[id] = null;
  443.                 if(cb)cb(self._bids[id]);
  444.                 return;
  445.             }
  446.             var bidUser = undefined;
  447.             var bidProduct = undefined;
  448.             var bidAdditionalDataCallback = function()
  449.             {
  450.                 if(bidUser === undefined
  451.                 || bidProduct === undefined)
  452.                     return;
  453.                 if(self._bids[id])
  454.                 {
  455.                     console.log("Tried to reload Bid #"+id+".");
  456.                     if(cb)cb(self._bids[id]);
  457.                     return;
  458.                 }
  459.                 var time = new Date( bidProduct.getStartTime().getTime()
  460.                                    + results[0].centiTime*10);
  461.                 self._bids[id] = new Bid(self, id, bidProduct,
  462.                                          new Date(time), bidUser);
  463.                 console.log("Loaded Bid #"+id+": Bid #? on "
  464.                     +JSON.stringify(bidProduct.getTitle()));
  465.                 if(cb)cb(self._bids[id]);
  466.             }
  467.             self.getUser(results[0].user, function(user)
  468.             {
  469.                 bidUser = user;
  470.                 bidAdditionalDataCallback();
  471.             });
  472.             self.getProduct(results[0].product, function(product)
  473.             {
  474.                 bidProduct = product;
  475.                 bidAdditionalDataCallback();
  476.             });
  477.         });
  478.     }
  479. }
  480.  
  481. function User(db, id, username)
  482. {
  483.     var self = this;
  484.  
  485.     this._database = db;
  486.     this._id = id;
  487.     this._username = username;
  488.  
  489.     this.getId = function()
  490.     {
  491.         return self._id;
  492.     }
  493.  
  494.     this.getUsername = function()
  495.     {
  496.         return self._username;
  497.     }
  498.  
  499.     /**
  500.      * Check a user's password. Calls a callback after checking is done. The
  501.      * callback will be called with a boolean as a first parameter, containing
  502.      * TRUE if the given passwordhash did match the password or FALSE otherwise.
  503.      */
  504.     this.checkPassword = function(passhash, cb)
  505.     {
  506.         self._database.query("SELECT COUNT(1) FROM users "
  507.                 +"WHERE id = ? AND password = UNHEX(?) LIMIT 1",
  508.         [self.getId(), passhash],
  509.         function(results)
  510.         {
  511.             if(cb)cb(results.length > 0);
  512.         });
  513.     }
  514.  
  515.     this.toJSON = function()
  516.     {
  517.         return {
  518.             id: self.getId(),
  519.             username: self.getUsername()
  520.         };
  521.     }
  522. }
  523.  
  524. function Product(db, id, title, thumbnail, value, time)
  525. {
  526.     var self = this;
  527.    
  528.     this._database = db;
  529.     this._id = id;
  530.     this._thumbnail = thumbnail;
  531.     this._value = value;
  532.     this._title = title;
  533.     this._time = time;
  534.     this._lastBid = undefined;
  535.  
  536.     this._init = function(cb)
  537.     {
  538.         self._database.query("SELECT id FROM bids WHERE product = ? "
  539.             +"ORDER BY centiTime DESC LIMIT 1",
  540.         [self.getId()],
  541.         function(results)
  542.         {
  543.             if(results.length == 0)
  544.             {
  545.                 self._lastBid = null;
  546.                 self._init = undefined;
  547.                 if(cb)cb(self);
  548.                 return;
  549.             }
  550.             db.getBid(results[0].id, function(bid)
  551.             {
  552.                 self._lastBid = bid;
  553.                 self._init = undefined;
  554.                 if(cb)cb(self);
  555.             });
  556.         });
  557.     }
  558.  
  559.     /** @var An array with on-bid-placed-event listeners. */
  560.     this._onBidPlacedEventListeners = [];
  561.  
  562.     /**
  563.      *
  564.      */
  565.     this._triggerOnBidPlacedEventListeners = function(bid)
  566.     {
  567.         for(var i=0; i<self._onBidPlacedEventListeners.length; i++)
  568.             self._onBidPlacedEventListeners[i](bid);
  569.     }
  570.  
  571.     /**
  572.      * Add a on-bid-placed-event-listener. The function will be called everytime
  573.      * a bid is placed on any product. The callback will be given a
  574.      * Bid-object which the bid was placed on as a first parameter.
  575.      * @param cb The event-listener.
  576.      */
  577.     this.addOnBidPlacedEventListener = function(cb)
  578.     {
  579.         self._onBidPlacedEventListeners.add(cb);
  580.     }
  581.  
  582.     this.removeOnBidPlacedEventListener = function(cb)
  583.     {
  584.         self._onBidPlacedEventListeners.remove(cb);
  585.     }
  586.  
  587.     /**
  588.      * Get the id of this product.
  589.      * @type Number
  590.      * @return the id
  591.      */
  592.     this.getId = function()
  593.     {
  594.         return self._id;
  595.     }
  596.  
  597.     this.getTitle = function()
  598.     {
  599.         return self._title;
  600.     }
  601.  
  602.     this.getThumbnail = function()
  603.     {
  604.         return self._thumbnail;
  605.     }
  606.  
  607.     this.getValue = function()
  608.     {
  609.         return self._value;
  610.     }
  611.  
  612.     /**
  613.      * Get the time this Product will start.
  614.      * @type Date
  615.      * @return The time
  616.      */
  617.     this.getStartTime = function()
  618.     {
  619.         return self._time;
  620.     }
  621.  
  622.     this.getLastBid = function()
  623.     {
  624.         return self._lastBid;
  625.     }
  626.  
  627.     this.placeBid = function(time, user, cb)
  628.     {
  629.         var centiTime = (time.getTime() - self.getStartTime().getTime())/10;
  630.         self._database.query(
  631.                 "INSERT INTO bids (product, centiTime, user) VALUES(?,?,?)",
  632.         [self.getId(), centiTime, user.getId()],
  633.         function(results)
  634.         {
  635.             db.getBid(results.insertId, function(bid)
  636.             {
  637.                 self._lastBid = bid;
  638.                 self._triggerOnBidPlacedEventListeners(bid);
  639.                 if(cb)cb(bid);
  640.             });
  641.         });
  642.     }
  643.  
  644.     this.toJSON = function()
  645.     {
  646.         var bid = self.getLastBid();
  647.         return {
  648.             id: self.getId(),
  649.             title: self.getTitle(),
  650.             time: self.getStartTime().getTime(),
  651.             thumbnail: self.getThumbnail(),
  652.             value: self.getValue(),
  653.             lastBid: !bid?null:{
  654.                 id: bid.getId(),
  655.                 time: bid.getTime().getTime(),
  656.                 user: {
  657.                     id: bid.getUser().getId(),
  658.                     username: bid.getUser().getUsername()
  659.                 }
  660.             }
  661.         };
  662.     }
  663. }
  664.  
  665. function Bid(db, id, product, time, user)
  666. {
  667.     var self = this;
  668.    
  669.     this._database = db;
  670.     this._id = id;
  671.     this._product = product;
  672.     this._time = time;
  673.     this._user = user;
  674.  
  675.     this.getId = function()
  676.     {
  677.         return self._id;
  678.     }
  679.  
  680.     /**
  681.      * Get the time this Bid was placed.
  682.      * @type Date
  683.      * @return The time
  684.      */
  685.     this.getTime = function()
  686.     {
  687.         return self._time;
  688.     }
  689.  
  690.     this.getProduct = function()
  691.     {
  692.         return self._product;
  693.     }
  694.  
  695.     this.getUser = function()
  696.     {
  697.         return self._user;
  698.     }
  699.  
  700.     this.toJSON = function()
  701.     {
  702.         return {
  703.             id: self.getId(),
  704.             time: self.getTime().getTime(),
  705.             user: self.getUser().toJSON(),
  706.             product: self.getProduct().toJSON()
  707.         };
  708.     }
  709. }
  710.  
  711. function handleJSONResponse(response)
  712. {
  713.     switch(response.getParam(0))
  714.     {
  715.         case "place-bid":
  716.             var bidProduct = undefined;
  717.             var bidUser = undefined;
  718.             var productAndUserFetchedCallback = function()
  719.             {
  720.                 if(bidProduct === undefined
  721.                 || bidUser === undefined)
  722.                     return;
  723.                 if(!bidUser||!bidProduct)
  724.                 {
  725.                     if(!bidUser)
  726.                         response.addError("Placing a bid requires a login.");
  727.                     if(!bidProduct)
  728.                         response.addError("Product does not exist.");
  729.                     response.end();
  730.                     return;
  731.                 }
  732.                 bidProduct.placeBid(response.getTime(), bidUser,
  733.                 function(bid)
  734.                 {
  735.                     response.set("bid", bid?bid.toJSON():null);
  736.                     response.end();
  737.                 });
  738.             }
  739.             db.getProduct(response.getParam(1), function(product)
  740.             {
  741.                 bidProduct = product;
  742.                 productAndUserFetchedCallback();
  743.             });
  744.             response.validateLogin(function(user)
  745.             {
  746.                 bidUser = user;
  747.                 productAndUserFetchedCallback();
  748.             });
  749.             break;
  750.         case "next-bid-since":
  751.             db.getBid(parseInt(response.getParam(1)), function(sinceBid)
  752.             {
  753.                 if(sinceBid != db.getLastBid())
  754.                 {
  755.                     db.getLastBidsPlacedAfterBid(sinceBid,
  756.                     function(bids)
  757.                     {
  758.                         var bidData = new Array(bids.length);
  759.                         for(var i=0; i<bidData.length; i++)
  760.                             bidData[i] = bids[i].toJSON();
  761.                         response.set("bids", bidData);
  762.                         response.end();
  763.                     });
  764.                 }
  765.                 else
  766.                 {
  767.                     db.addOnBidPlacedEventListener(function(bid)
  768.                     {
  769.                         response.set("bids", [bid]);
  770.                         response.end();
  771.                     });
  772.                 }
  773.             });
  774.             break;
  775.         case "active-products":
  776.             db.getProductsStartingBetween(new Date(0), new Date(), function(products)
  777.             {
  778.                 var productData = new Array(products.length);
  779.                 for(var i=0; i<productData.length; i++)
  780.                     productData[i] = products[i].toJSON();
  781.                 response.set("active-products", productData);
  782.                 response.end();
  783.             });
  784.             break;
  785.         case "product-info":
  786.             db.getProduct(response.getParam(1), function(product)
  787.             {
  788.                 var bid = product.getLastBid();
  789.                 response.set("product", product?product.toJSON():null);
  790.                 response.end();
  791.             });
  792.             break;
  793.         case "time":
  794.             response.set("time", response.getTime().getTime());
  795.             response.end();
  796.             break;
  797.         default:
  798.             response.addError("Unknown Command");
  799.             response.end();
  800.     }
  801. }
  802.  
  803. var client = mysql.Client();
  804. client.host = settings.sqlHost;
  805. client.user = settings.sqlUser;
  806. client.password = settings.sqlPass;
  807. client.database = settings.sqlDatabase;
  808.  
  809. client.connect();
  810.  
  811. var db = new Database(client);
  812. db._init(function(db)
  813. {
  814.     http.createServer(function(request, response)
  815.     {
  816.         var jsonresponse = new JSONResponse(db, request, response);
  817.         handleJSONResponse(jsonresponse);
  818.     }).listen(settings.httpPort);
  819. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement