From d5cefd6edc89a7ce436757a872ee145717fcf809 Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Sun, 6 Oct 2019 11:38:28 +0200 Subject: [PATCH] ping: Reworked get request output for ip addresses - Rewrote code - Replaced missing addresses with empty addresses - Added timestamps of last update --- routes/ping.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/routes/ping.js b/routes/ping.js index 6efe862..bca28bc 100644 --- a/routes/ping.js +++ b/routes/ping.js @@ -33,7 +33,12 @@ router.get("/:fqdn", (req, res) => { db.q.select(IP_TYPES).from("addresses").filter("fqdn", req.params.fqdn).first((e, d) => { if (e) return res.status(400).send("Error"); if (!d) return res.status(404).send("Unknown FQDN"); - res.send(d.ipv4 ? (d.ipv6 ? d.ipv4 + "\n" + d.ipv6 : d.ipv4) : (d.ipv6 ? d.ipv6 : "")); + res.send([ + d.ipv4 ? d.ipv4 : "0.0.0.0", + d.ipv4LastPing + d.ipv6 ? d.ipv6 : "::", + d.ipv6LastPing + ].reduce((a, b) => a + "\n" + b)); }); });