commit 00591020d5df7f09207c996ece539912eba0a8f4
parent 71f55746d8ee42c3be4cd93fbf6c08cf7081bd19
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Wed, 2 Oct 2024 10:45:22 -0700
Utilize devapi developer setting for api requests
When set, the API host is set to the current web host and the http
protocol is used instead of https.
Diffstat:
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/files/lib/api.js b/files/lib/api.js
@@ -1,6 +1,19 @@
-const proto = "http"
-const host = "api.spaceplanner.app"
-const version = "v0"
+import * as dev from "/lib/dev.js"
+
+let config = {
+ proto: "https",
+ host: "api.spaceplanner.app",
+ version: "v0"
+}
+
+if (dev.setting("devapi")) {
+ console.warn("Using testing API")
+ config.proto = "http"
+ let url = new URL(document.URL)
+ config.host = url.host
+}
+
+console.log(`Floorplan API: ${config.proto}://${config.host}/${config.version}`)
function verify_response(response) {
let type = response.headers.get("Content-Type")
@@ -42,7 +55,7 @@ function api_fetch(method, endpoint, body) {
params["body"] = JSON.stringify(body)
}
- return fetch(proto + "://" + host + "/" + version + "/" + requestPath(endpoint), params)
+ return fetch(config.proto + "://" + config.host + "/" + config.version + "/" + requestPath(endpoint), params)
.then(verify_response)
.then(parse_response)
.then(status)