diff options
| author | Shulhan <ms@kilabit.info> | 2022-04-24 17:56:11 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-04-25 01:50:39 +0700 |
| commit | a619e95df4d64ca7a8ddf41d996b62dc23334f9f (patch) | |
| tree | e070ae42070e8dad06c9f8e069b1cc47c7d6cde2 /_www/rescached.js | |
| parent | f30942daafd60a629a17cb08beeca6e4bb86aa93 (diff) | |
| download | rescached-a619e95df4d64ca7a8ddf41d996b62dc23334f9f.tar.xz | |
all: refactor the APIs to manage hosts.d resource records (RR)
There are two APIs to manage hosts.d RR: create and delete.
Previously, the create API pass the hosts name inside and values inside
the path,
POST /hosts.d/<name>/rr?domain=&value=
This commit changes the request type to form, so all parameters move
to body,
POST /hosts.d/rr
Content-Type: application/x-www-form-urlencoded
name=&domain=&value=
On delete API, we changes the name parameter to be send on query
parameter along with domain to be deleted.
Previously, the delete API was
DELETE /hosts.d/<name>/rr?domain=
now it become
DELETE /hosts.d/rr?name=&domain=
Diffstat (limited to '_www/rescached.js')
| -rw-r--r-- | _www/rescached.js | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/_www/rescached.js b/_www/rescached.js index 8d03daf..15d7673 100644 --- a/_www/rescached.js +++ b/_www/rescached.js @@ -40,6 +40,7 @@ class Rescached { static apiCaches = "/api/caches" static apiCachesSearch = "/api/caches/search" static apiHostsd = "/api/hosts.d" + static apiHostsdRR = "/api/hosts.d/rr" static apiZoned = "/api/zone.d/" constructor(server) { @@ -159,7 +160,7 @@ class Rescached { var params = new URLSearchParams() params.set(paramNameName, name) - var url = Rescached.apiHostsd + "?"+ params.toString() + var url = Rescached.apiHostsd + "?" + params.toString() const httpRes = await fetch(url) let res = await httpRes.json() @@ -172,21 +173,18 @@ class Rescached { return res } - async HostsFileRecordAdd(hostsFile, domain, value) { + async HostsdRecordAdd(hostsFile, domain, value) { let params = new URLSearchParams() + params.set("name", hostsFile) params.set("domain", domain) params.set("value", value) - const api = - this.server + - Rescached.apiHostsd + - hostsFile + - "/rr" + - "?" + - params.toString() - - const httpRes = await fetch(api, { + const httpRes = await fetch(Rescached.apiHostsdRR, { method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, + body: params.toString(), }) const res = await httpRes.json() if (httpRes.Status === 200) { @@ -196,17 +194,12 @@ class Rescached { return res } - async HostsFileRecordDelete(hostsFile, domain) { + async HostsdRecordDelete(hostsFile, domain) { let params = new URLSearchParams() + params.set("name", hostsFile) params.set("domain", domain) - const api = - this.server + - Rescached.apiHostsd + - hostsFile + - "/rr" + - "?" + - params.toString() + const api = Rescached.apiHostsdRR + "?" + params.toString() const httpRes = await fetch(api, { method: "DELETE", |
