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