Skip to content

Commit

Permalink
Merge pull request #220 from CloudBoost/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
shubhamqweasd authored Jul 21, 2017
2 parents 2ca3d7a + 1ab0e55 commit e517f38
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 44 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
44 changes: 22 additions & 22 deletions database-connect/mongoConnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,65 +9,65 @@
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<global.config.mongo.length; i++){
servers.push(new Server(global.config.mongo[i].host,parseInt(global.config.mongo[i].port)));
for (var i = 0; i < global.config.mongo.length; i++) {
servers.push(new Server(global.config.mongo[i].host, parseInt(global.config.mongo[i].port)));
}

var replSet = new ReplSet(servers);

return replSet;

}catch(e){
global.winston.log('error',{"error":String(e),"stack": new Error().stack});
return [];
} catch (e) {
global.winston.log('error', { "error": String(e), "stack": new Error().stack });
return [];
}
},

connect: function() {
connect: function () {

var deferred = q.defer();
try{
try {
var mongoClient = require('mongodb').MongoClient;
mongoClient.connect(global.keys.mongoConnectionString,function (err, db) {
mongoClient.connect(global.keys.mongoConnectionString, function (err, db) {
if (err) {
deferred.reject(err);
} else {
deferred.resolve(db);
}
});

}catch(e){
global.winston.log('error',{"error":String(e),"stack": new Error().stack});
deferred.reject(e);
} catch (e) {
global.winston.log('error', { "error": String(e), "stack": new Error().stack });
deferred.reject(e);
}
return deferred.promise;
}
Expand Down
4 changes: 2 additions & 2 deletions databases/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
});
}
Expand Down
34 changes: 19 additions & 15 deletions dbUtil/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
1 change: 1 addition & 0 deletions helpers/socketQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 4 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -796,6 +793,8 @@ function servicesKickstart() {
}, function(err) {
console.log("Cannot connect to MongoDB.");
console.log(err);
// exit server if connection to mongo was not made
process.exit(1)
});

} catch (err) {
Expand Down Expand Up @@ -824,7 +823,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) {
Expand Down

0 comments on commit e517f38

Please sign in to comment.