diff --git a/README.md b/README.md index de1fa55..8319009 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This repository contains the code for my personal web API written in JavaScript using the Express framework. ## Documentation -This file contains documentation relevant for development and deployment, but not necessarily usage. Information for all endpoints is available [on my website](https://music.youtube.com/watch?v=n2LxBXS4jJM&si=ZpzGNBGvQp1cFicW). +This file contains documentation relevant for development and deployment, but not necessarily usage. Information for all endpoints is available [on my website](https://enstrayed.com/posts/20240409-API-Documentation.html). ## Issues If you would like to report a bug or security issue, please open a GitHub issue. If you are the operator of a service this application accesses, use the contact information provided during registration with your service to contact me directly. diff --git a/liberals/authorization.js b/liberals/authorization.js index 4ca6348..49a14ed 100644 --- a/liberals/authorization.js +++ b/liberals/authorization.js @@ -1,11 +1,7 @@ const { globalConfig } = require("../index.js") async function checkAuthorization(documentToUse,keyToCheck) { - return await fetch(`http://${globalConfig.couchdb.host}/apiauthkeys/${documentToUse}`, { - headers: { - "Authorization": `Basic ${btoa(globalConfig.couchdb.authorization)}` - } - }).then(fetchRes => { + return await fetch(`${globalConfig.couchdbHost}/apiauthkeys/${documentToUse}`).then(fetchRes => { if (fetchRes.status === 404) { // If document doesnt exist fail gracefully diff --git a/routes/etyd.js b/routes/etyd.js index ca39d10..60b9cd8 100644 --- a/routes/etyd.js +++ b/routes/etyd.js @@ -2,11 +2,7 @@ const { app, globalConfig } = require("../index.js") // Get globals from index const { checkAuthorization } = require("../liberals/authorization.js") app.get("/etyd*", (rreq,rres) => { - fetch(`http://${globalConfig.couchdb.host}/etyd${rreq.path.replace("/etyd","")}`, { - headers: { - "Authorization": `Basic ${btoa(globalConfig.couchdb.authorization)}` - } - }).then(dbRes => { + fetch(`${globalConfig.couchdbHost}/etyd${rreq.path.replace("/etyd","")}`).then(dbRes => { if (dbRes.status == 404) { rres.sendStatus(404) } else { @@ -36,21 +32,16 @@ app.delete("/etyd*", (rreq,rres) => { rres.sendStatus(401) } else if (authRes === true) { // Authorization successful - fetch(`http://${globalConfig.couchdb.host}/etyd${rreq.path.replace("/etyd", "")}`, { - headers: { - "Authorization": `Basic ${btoa(globalConfig.couchdb.authorization)}` - } - }).then(dbRes => { + fetch(`${globalConfig.couchdbHost}/etyd${rreq.path.replace("/etyd", "")}`).then(dbRes => { if (dbRes.status == 404) { rres.sendStatus(404) } else { dbRes.json().then(dbRes => { - fetch(`http://${globalConfig.couchdb.host}/etyd${rreq.path.replace("/etyd", "")}`, { + fetch(`${globalConfig.couchdbHost}/etyd${rreq.path.replace("/etyd", "")}`, { method: "DELETE", headers: { - "Authorization": `Basic ${btoa(globalConfig.couchdb.authorization)}`, "If-Match": dbRes["_rev"] // Using the If-Match header is easiest for deleting entries in couchdb } }).then(fetchRes => { @@ -92,10 +83,7 @@ app.post("/etyd*", (rreq,rres) => { console.log(`${rreq.get("cf-connecting-ip")} POST ${rreq.path} returned 400 KEY: ${rreq.get("Authorization")}`) rres.sendStatus(400) } else { - fetch(`http://${globalConfig.couchdb.host}/etyd${rreq.path.replace("/etyd", "")}`, { - headers: { - "Authorization": `Basic ${btoa(globalConfig.couchdb.authorization)}` - }, + fetch(`${globalConfig.couchdbHost}/etyd${rreq.path.replace("/etyd", "")}`, { method: "PUT", body: JSON.stringify({ "content": {