|
|
|
@ -118,6 +118,8 @@ class Xapi {
|
|
|
|
|
stat.tables = 0 |
|
|
|
|
stat.apis = 0 |
|
|
|
|
|
|
|
|
|
// console.log('this.config while setting up routes', this.config);
|
|
|
|
|
|
|
|
|
|
// show routes for database schema
|
|
|
|
|
this.app.get('/', this.asyncMiddleware(this.root.bind(this))) |
|
|
|
|
|
|
|
|
@ -128,7 +130,7 @@ class Xapi {
|
|
|
|
|
this.app.route(this.config.apiPrefix + 'xjoin') |
|
|
|
|
.get(this.asyncMiddleware(this.xjoin.bind(this))); |
|
|
|
|
|
|
|
|
|
stat.api += 3; |
|
|
|
|
stat.apis += 3; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************** START : setup routes for each table ****************/ |
|
|
|
@ -164,6 +166,7 @@ class Xapi {
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'create': |
|
|
|
|
if (!this.config.readOnly) |
|
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
|
.post(this.asyncMiddleware(resourceCtrl.create.bind(resourceCtrl))); |
|
|
|
|
break; |
|
|
|
@ -174,33 +177,55 @@ class Xapi {
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'bulkInsert': |
|
|
|
|
if (!this.config.readOnly) { |
|
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
|
.post(this.asyncMiddleware(resourceCtrl.bulkInsert.bind(resourceCtrl))); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'bulkRead': |
|
|
|
|
if (!this.config.readOnly){ |
|
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
|
.get(this.asyncMiddleware(resourceCtrl.bulkRead.bind(resourceCtrl))); |
|
|
|
|
} else { |
|
|
|
|
stat.apis--; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'bulkDelete': |
|
|
|
|
if (!this.config.readOnly){ |
|
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
|
.delete(this.asyncMiddleware(resourceCtrl.bulkDelete.bind(resourceCtrl))); |
|
|
|
|
} else { |
|
|
|
|
stat.apis--; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'patch': |
|
|
|
|
if (!this.config.readOnly){ |
|
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
|
.patch(this.asyncMiddleware(resourceCtrl.patch.bind(resourceCtrl))); |
|
|
|
|
} else { |
|
|
|
|
stat.apis--; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'update': |
|
|
|
|
if (!this.config.readOnly){ |
|
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
|
.put(this.asyncMiddleware(resourceCtrl.update.bind(resourceCtrl))); |
|
|
|
|
} else { |
|
|
|
|
stat.apis--; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'delete': |
|
|
|
|
if (!this.config.readOnly){ |
|
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
|
.delete(this.asyncMiddleware(resourceCtrl.delete.bind(resourceCtrl))); |
|
|
|
|
} else { |
|
|
|
|
stat.apis--; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'exists': |
|
|
|
@ -259,7 +284,7 @@ class Xapi {
|
|
|
|
|
/**************** END : setup routes for each table ****************/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.config.dynamic === 1) { |
|
|
|
|
if (this.config.dynamic === 1 && !this.config.readOnly) { |
|
|
|
|
|
|
|
|
|
this.app.route('/dynamic*') |
|
|
|
|
.post(this.asyncMiddleware(this.runQuery.bind(this))); |
|
|
|
@ -270,16 +295,17 @@ class Xapi {
|
|
|
|
|
this.app.get('/download', this.downloadFile.bind(this)); |
|
|
|
|
/**************** END : multer routes ****************/ |
|
|
|
|
|
|
|
|
|
stat.apis += 4; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**************** START : health and version ****************/ |
|
|
|
|
this.app.get('/_health', this.asyncMiddleware(this.health.bind(this))); |
|
|
|
|
this.app.get('/_version', this.asyncMiddleware(this.version.bind(this))); |
|
|
|
|
stat.apis += 2; |
|
|
|
|
/**************** END : health and version ****************/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stat.api += 4; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let statStr = ' Generated: ' + stat.apis + ' REST APIs for ' + stat.tables + ' tables ' |
|
|
|
|
|
|
|
|
|
console.log(' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '); |
|
|
|
@ -304,7 +330,7 @@ class Xapi {
|
|
|
|
|
this.mysql.prepareJoinQuery(req, res, obj) |
|
|
|
|
|
|
|
|
|
//console.log(obj);
|
|
|
|
|
if(obj.query.length){ |
|
|
|
|
if (obj.query.length) { |
|
|
|
|
let results = await this.mysql.exec(obj.query, obj.params) |
|
|
|
|
res.status(200).json(results) |
|
|
|
|
} else { |
|
|
|
|