From 89f2bfecdb0c5cd9ffdabbca54d4e46bfd894651 Mon Sep 17 00:00:00 2001 From: Enstrayed <48845980+Enstrayed@users.noreply.github.com> Date: Thu, 2 May 2024 17:32:03 -0700 Subject: [PATCH] working changes --- routes/etyd.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/routes/etyd.js b/routes/etyd.js index 699fd0e..1d8235c 100644 --- a/routes/etyd.js +++ b/routes/etyd.js @@ -84,6 +84,55 @@ app.delete("/etyd*", (rreq,rres) => { }) +// app.post("/etyd*", (rreq,rres) => { + +// fetch(`http://${globalConfig.couchdb.host}/apiauthkeys/${globalConfig.etyd.authKeysDoc}`, { +// headers: { +// "Authorization": `Basic ${btoa(globalConfig.couchdb.authorization)}` +// } +// }).then(dbRes => dbRes.json()).then(dbRes => { + +// if (dbRes.status == 404) { // If document containing cider auth keys does not exist +// console.log(`ERROR: Could not find apiauthkeys/${globalConfig.etyd.authKeysDoc}`) +// rres.sendStatus(500) // Refuse request +// } else { +// if (rreq.get("Authorization") == null) { // If authorization header is not supplied +// rres.sendStatus(400) // then return bad request (would return 500 otherwise) +// } else { +// if (dbRes["content"][rreq.get("Authorization").split("_")[0]] === rreq.get("Authorization").split("_")[1]) { + +// fetch(`http://${globalConfig.couchdb.host}/etyd${rreq.path.replace("/etyd", "")}`, { +// headers: { +// "Authorization": `Basic ${btoa(globalConfig.couchdb.authorization)}` +// } +// }).then(dbRes => { + +// if (dbRes.status !== 404) { +// console.log(`${rres.get("cf-connecting-ip")} POST ${rreq.path} returned 409 KEY: ${rreq.get("Authorization")}`) +// rres.sendStatus(409) +// } else { + + + +// } + +// }).catch(fetchError => { +// rres.sendStatus(500) +// console.log(`${rres.get("cf-connecting-ip")} DELETE ${rreq.path} returned 500: ${fetchError}`) +// }) + +// } else { +// console.log(`${rreq.get("cf-connecting-ip")} DELETE ${rreq.path} returned 401`) // log ip of unauthorized requests +// rres.sendStatus(401) // received auth key was not in database +// } +// } +// } +// }).catch(fetchError => { +// rres.sendStatus(500) +// console.log(`${rres.get("cf-connecting-ip")} DELETE ${rreq.path} returned 500: ${fetchError}`) +// }) + +// }) module.exports = {app} // export routes to be imported by index for execution \ No newline at end of file