From edcf6061e5efbe1b60bc1d17ff4bbe83ae866a09 Mon Sep 17 00:00:00 2001
From: alex <alex@alexloehr.net>
Date: Tue, 23 Jun 2026 16:12:11 +0000
Subject: [PATCH] adding route /api/ping

---
 app.js              |   11 +++++++++++
 test/testApiPing.js |   41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/app.js b/app.js
index d784498..5c21238 100644
--- a/app.js
+++ b/app.js
@@ -337,6 +337,17 @@
       }
    })
 
+   /////// system ////////////////////////////////////////////////////////////////
+
+   .post("/api/ping", async function (req, res) {
+      try {
+         const res2 = await libIlias.ping()
+         return res.send(res2)
+      } catch (err) {
+         console.error(err)
+         return res.code(500).send({status: "error", error: err.toString()})
+      }
+   })
 
 
 /////// STATIC / SPA ////////////////////////////////////////////////////////////////
diff --git a/test/testApiPing.js b/test/testApiPing.js
new file mode 100644
index 0000000..06670ed
--- /dev/null
+++ b/test/testApiPing.js
@@ -0,0 +1,41 @@
+const expect = require("chai").expect
+
+const settings = require("../settings")
+
+/////////////////////////////////////////////////////////////////////////
+
+function getUrl(ref_id) {
+    return `http://localhost:${settings.port}/api/ping?token=${settings.authtoken}`
+}
+
+const ref_id = 595
+
+describe("using the API", function () {
+
+    describe("the Route POST /api/ping", function () {
+
+        it("should return an answer from php component", async function () {
+            const url = getUrl(ref_id)
+            console.log(url)
+            const res = await fetch(url, {
+                method: "POST",
+                body: JSON.stringify({}),
+                headers: {
+                    'Content-Type': 'application/json', // Indicate JSON data
+                },
+            })
+            // console.log(res)
+            const data = await res.json()
+            console.log(data)
+
+            expect(data).to.be.a("object")
+            expect(data.status).to.equal("ok")
+            expect(data.msg).to.equal("pong")
+        })
+
+    })
+
+})
+
+/////////////////////////////////////////////////////////////////////////
+

--
Gitblit v1.8.0