From c4a4f07218f282c26118bf86f19cce6f71566de1 Mon Sep 17 00:00:00 2001 From: Ritish Gumber Date: Thu, 6 Jul 2017 20:28:04 +0530 Subject: [PATCH 1/4] handle 404 err --- server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.js b/server.js index 9429f120..fd201a10 100644 --- a/server.js +++ b/server.js @@ -824,7 +824,7 @@ function attachCronJobs() { require('./cron/expire.js'); app.use(function(req,res,next){ - res.status(404).json({status : 404,message : 'The endpoint was not found. Please check.'}); + res.json({status : 404,message : 'The endpoint was not found. Please check.'}); }); } catch (err) { From 8a104793e4e8797fe1f45664d9889fbdb534a49e Mon Sep 17 00:00:00 2001 From: shubhamqweasd Date: Mon, 10 Jul 2017 16:42:32 +0530 Subject: [PATCH 2/4] gracefull exit on mongo error --- database-connect/mongoConnect.js | 44 ++++++++++++++++---------------- server.js | 2 ++ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/database-connect/mongoConnect.js b/database-connect/mongoConnect.js index f98204d5..20ee3767 100644 --- a/database-connect/mongoConnect.js +++ b/database-connect/mongoConnect.js @@ -9,55 +9,55 @@ var q = require("q"); module.exports = function () { - + var obj = { - dbConnect: function(appId){ - try{ + dbConnect: function (appId) { + try { return global.mongoClient.db(appId); - }catch(e){ - global.winston.log('error',{"error":String(e),"stack": new Error().stack}); + } catch (e) { + global.winston.log('error', { "error": String(e), "stack": new Error().stack }); } }, - replSet : function(){ + replSet: function () { - try{ + try { var ReplSet = require('mongodb').ReplSet, - Server = require('mongodb').Server; + Server = require('mongodb').Server; var servers = []; - if(global.config.mongo.length===0){ + if (global.config.mongo.length === 0) { return null; } - if(global.config.mongo.length===1){ + if (global.config.mongo.length === 1) { return new Server(global.config.mongo[0].host, global.config.mongo[0].port); } - for(var i=0;i Date: Sun, 16 Jul 2017 13:33:43 -0400 Subject: [PATCH 3/4] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index d4f0a9d9..66f6916c 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,10 @@ curl -H "Content-Type: application/json" -X POST -d '{"secureKey":"xxxxxx-yyyy-x ``` +### Creating a table + +Table lets you store any structured data in your app. To create one, [check this documentation out](https://tutorials.cloudboost.io/en/schema/cloudtables). + ### Delete an app To delete an app, You need to : From 0293eb1ff2f01dee6ed0c57e71241e2233150514 Mon Sep 17 00:00:00 2001 From: shubhamqweasd Date: Fri, 21 Jul 2017 17:06:43 +0530 Subject: [PATCH 4/4] fixed indexing for geopoint, remove un-needed logs --- databases/mongo.js | 4 ++-- dbUtil/mongo.js | 34 +++++++++++++++++++--------------- helpers/socketQuery.js | 1 + server.js | 5 +---- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/databases/mongo.js b/databases/mongo.js index 9aa1d9eb..ac8e72b6 100644 --- a/databases/mongo.js +++ b/databases/mongo.js @@ -376,7 +376,7 @@ module.exports = function() { findQuery.toArray(function(err, docs) { if (err) { - global.winston.log('error', err); + console.log('error', err); deferred.reject(err); } else { if (!include || include.length === 0) { @@ -386,7 +386,7 @@ module.exports = function() { obj.document._include(appId, include, docs).then(function(docs) { deferred.resolve(docs); }, function(error) { - global.winston.log('error', error); + console.log('error', error); deferred.reject(error); }); } diff --git a/dbUtil/mongo.js b/dbUtil/mongo.js index cfbe22df..6c246fce 100644 --- a/dbUtil/mongo.js +++ b/dbUtil/mongo.js @@ -243,25 +243,29 @@ module.exports = function() { Creating a wild card index , instaed of creating individual $text index on each column seperately **/ var obj = {}; + + if(columnType === 'Text'){ + obj["$**"] = "text"; + } if (columnType === 'GeoPoint') { obj[columnName] = "2dsphere"; } - var collection = global.mongoClient.db(appId).collection(global.mongoUtil.collection.getId(appId, collectionName)); - collection.createIndex({ - "$**": "text" - }, function(err, res) { - if (err) { - global.winston.log('error', err); - console.log("Could not create index"); - deferred.reject(err); - } else { - // create geopoint indexing explicitly - collection.createIndex(obj); - console.log(res); - deferred.resolve(res); - } - }); + if(Object.keys(obj).length > 0){ + var collection = global.mongoClient.db(appId).collection(global.mongoUtil.collection.getId(appId, collectionName)); + collection.createIndex(obj, function(err, res) { + if (err) { + console.log("Could not create index", err); + deferred.reject(err); + } else { + console.log(res); + deferred.resolve(res); + } + + }); + } else { + deferred.resolve('NO index'); + } } catch (err) { global.winston.log('error', { diff --git a/helpers/socketQuery.js b/helpers/socketQuery.js index 566e488f..d948a1fe 100644 --- a/helpers/socketQuery.js +++ b/helpers/socketQuery.js @@ -30,6 +30,7 @@ module.exports = { */ setData: function(socketId, data, callback) { try { + data = data || {} global.redisClient.set('cb-socket-' + socketId + '-data' + data.eventType, JSON.stringify(data), function(err, reply) { if (callback) callback(err, reply); diff --git a/server.js b/server.js index 729b8944..2ea0e948 100644 --- a/server.js +++ b/server.js @@ -243,10 +243,7 @@ global.app.use([ } }, function(err) { - global.winston.log('error', { - "error": String(err), - "stack": new Error().stack - }); + console.log(err.message) return res.status(500).send(err.message); }); }