From 3698772318a780166c476e8c56b6ff9868c9e7ec Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Fri, 23 Jul 2021 05:02:52 -0500 Subject: [PATCH] Add dynamic endpoint generation --- server.js | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 6a069c1..497401d 100644 --- a/server.js +++ b/server.js @@ -51,9 +51,131 @@ const ENDPOINTDATA=[ requiredfields:["name","icon"], optionalfields:[], excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"class_level_data", + requiredfields:["name","icon"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"class_weapon_type_data", + requiredfields:["name","icon"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"weapon", + requiredfields:["name","icon"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"weapon_existence_data", + requiredfields:["name","icon"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"weapon_type", + requiredfields:["name","icon"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"armor", + requiredfields:["name","icon"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"potential", + requiredfields:["name","icon"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"potential_data", + requiredfields:["name","icon"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"builds", + requiredfields:["name","icon"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"skill", + requiredfields:["name","icon"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"skill_type", + requiredfields:["name","icon"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"skill_data", + requiredfields:["name","icon"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"augment", + requiredfields:["name","icon"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"augment_type", + requiredfields:["name","icon"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"food", + requiredfields:["name","icon"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"food_mult", + requiredfields:["name","icon"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"roles", + requiredfields:["name","icon"], + optionalfields:[], + excludedfields:[] //Fields to not output in GET. + }, + { + endpoint:"users", + requiredfields:["name","icon"], + optionalfields:[], + excludedfields:["password_hash"] //Fields to not output in GET. } ] +function CreateDynamicEndpoints() { + ENDPOINTDATA.map((endpoint)=>{ + app.get("/"+endpoint.endpoint,(req,res)=>{ + db.query('select * from '+endpoint.endpoint) + .then((data)=>{ + res.status(200).json({fields:data.fields,rows:data.rows}) + }) + .catch((err)=>{ + res.status(500).send(err.message) + }) + }) + }) +} + function CleanUp(arr,vals){ return arr.map((arrVal)=>{ vals.forEach((val)=>{ @@ -109,4 +231,6 @@ app.get('/data',(req,res)=>{ .catch((err)=>{ res.status(500).send(err.message); }) -}) \ No newline at end of file +}) + +CreateDynamicEndpoints() \ No newline at end of file