|
|
@ -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,6 +166,7 @@ class Xapi { |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'create': |
|
|
|
case 'create': |
|
|
|
|
|
|
|
if (!this.config.readOnly) |
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
.post(this.asyncMiddleware(resourceCtrl.create.bind(resourceCtrl))); |
|
|
|
.post(this.asyncMiddleware(resourceCtrl.create.bind(resourceCtrl))); |
|
|
|
break; |
|
|
|
break; |
|
|
@ -174,33 +177,55 @@ class Xapi { |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'bulkInsert': |
|
|
|
case 'bulkInsert': |
|
|
|
|
|
|
|
if (!this.config.readOnly) { |
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
.post(this.asyncMiddleware(resourceCtrl.bulkInsert.bind(resourceCtrl))); |
|
|
|
.post(this.asyncMiddleware(resourceCtrl.bulkInsert.bind(resourceCtrl))); |
|
|
|
|
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'bulkRead': |
|
|
|
case 'bulkRead': |
|
|
|
|
|
|
|
if (!this.config.readOnly){ |
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
.get(this.asyncMiddleware(resourceCtrl.bulkRead.bind(resourceCtrl))); |
|
|
|
.get(this.asyncMiddleware(resourceCtrl.bulkRead.bind(resourceCtrl))); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
stat.apis--; |
|
|
|
|
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'bulkDelete': |
|
|
|
case 'bulkDelete': |
|
|
|
|
|
|
|
if (!this.config.readOnly){ |
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
.delete(this.asyncMiddleware(resourceCtrl.bulkDelete.bind(resourceCtrl))); |
|
|
|
.delete(this.asyncMiddleware(resourceCtrl.bulkDelete.bind(resourceCtrl))); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
stat.apis--; |
|
|
|
|
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'patch': |
|
|
|
case 'patch': |
|
|
|
|
|
|
|
if (!this.config.readOnly){ |
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
.patch(this.asyncMiddleware(resourceCtrl.patch.bind(resourceCtrl))); |
|
|
|
.patch(this.asyncMiddleware(resourceCtrl.patch.bind(resourceCtrl))); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
stat.apis--; |
|
|
|
|
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'update': |
|
|
|
case 'update': |
|
|
|
|
|
|
|
if (!this.config.readOnly){ |
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
.put(this.asyncMiddleware(resourceCtrl.update.bind(resourceCtrl))); |
|
|
|
.put(this.asyncMiddleware(resourceCtrl.update.bind(resourceCtrl))); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
stat.apis--; |
|
|
|
|
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'delete': |
|
|
|
case 'delete': |
|
|
|
|
|
|
|
if (!this.config.readOnly){ |
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
this.app.route(routes[i]['routeUrl']) |
|
|
|
.delete(this.asyncMiddleware(resourceCtrl.delete.bind(resourceCtrl))); |
|
|
|
.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,16 +295,17 @@ class Xapi { |
|
|
|
this.app.get('/download', this.downloadFile.bind(this)); |
|
|
|
this.app.get('/download', this.downloadFile.bind(this)); |
|
|
|
/**************** END : multer routes ****************/ |
|
|
|
/**************** END : multer routes ****************/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stat.apis += 4; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**************** START : health and version ****************/ |
|
|
|
/**************** START : health and version ****************/ |
|
|
|
this.app.get('/_health', this.asyncMiddleware(this.health.bind(this))); |
|
|
|
this.app.get('/_health', this.asyncMiddleware(this.health.bind(this))); |
|
|
|
this.app.get('/_version', this.asyncMiddleware(this.version.bind(this))); |
|
|
|
this.app.get('/_version', this.asyncMiddleware(this.version.bind(this))); |
|
|
|
|
|
|
|
stat.apis += 2; |
|
|
|
/**************** END : health and version ****************/ |
|
|
|
/**************** END : health and version ****************/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stat.api += 4; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let statStr = ' Generated: ' + stat.apis + ' REST APIs for ' + stat.tables + ' tables ' |
|
|
|
let statStr = ' Generated: ' + stat.apis + ' REST APIs for ' + stat.tables + ' tables ' |
|
|
|
|
|
|
|
|
|
|
|
console.log(' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '); |
|
|
|
console.log(' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '); |
|
|
|