diff options
| author | Alex Pooley <zuedev@gmail.com> | 2025-03-19 05:27:35 +0000 |
|---|---|---|
| committer | Alex Pooley <zuedev@gmail.com> | 2025-03-19 05:27:35 +0000 |
| commit | 2d656ad02509d71b8793db5e75715f91f6e7b3fc (patch) | |
| tree | abd18cbaebf1a3ec7007e01f9f21df22af7e3881 | |
| parent | 3c4a86abee839a70eef202b2971bfe2fbf122f8d (diff) | |
| download | zue.dev-2d656ad02509d71b8793db5e75715f91f6e7b3fc.tar zue.dev-2d656ad02509d71b8793db5e75715f91f6e7b3fc.tar.gz zue.dev-2d656ad02509d71b8793db5e75715f91f6e7b3fc.tar.bz2 zue.dev-2d656ad02509d71b8793db5e75715f91f6e7b3fc.tar.xz zue.dev-2d656ad02509d71b8793db5e75715f91f6e7b3fc.zip | |
feat: implement service status validation and refactor status route
| -rw-r--r-- | source/index.js | 37 | ||||
| -rw-r--r-- | source/library/service_status.js | 24 |
2 files changed, 31 insertions, 30 deletions
diff --git a/source/index.js b/source/index.js index 5fe6c8b..472f7f1 100644 --- a/source/index.js +++ b/source/index.js @@ -1,19 +1,21 @@ import { Hono } from "hono"; import { cors } from "hono/cors"; +import service_status from "./library/service_status"; + const app = new Hono(); -// unlock cors for all routes +// enable cors for all routes app.use("*", cors()); -// return a simple message +// return a simple hello world message app.get("/", (context) => { return context.json({ message: "Hello, World! :3", }); }); -// return own status of the server +// return status of api itself app.get("/status", (context) => { return context.json({ status: "ok", @@ -24,33 +26,8 @@ app.get("/status", (context) => { app.get("/status/:service", (context) => { const { service } = context.req.param(); - const acceptedServices = [ - "dns", - "load-balancer", - "cdn", - "functions", - "mysql-cluster", - "mongodb-cluster", - "redis-cluster", - "elasticsearch-cluster", - "git-connector", - "job-runners", - "container-registry", - "kubernetes-cluster", - "bare-metal-servers", - "game-server-api", - "anti-ddos-protection", - "anti-cheat-api", - ]; - - if (!acceptedServices.includes(service)) { - return context.json( - { - error: "unknown service", - }, - 400 - ); - } + if (!service_status(service)) + return context.json({ error: "unknown service" }, 400); return context.json({ status: "ok", diff --git a/source/library/service_status.js b/source/library/service_status.js new file mode 100644 index 0000000..96c02b2 --- /dev/null +++ b/source/library/service_status.js @@ -0,0 +1,24 @@ +export default (service) => { + const acceptedServices = [ + "dns", + "load-balancer", + "cdn", + "functions", + "mysql-cluster", + "mongodb-cluster", + "redis-cluster", + "elasticsearch-cluster", + "git-connector", + "job-runners", + "container-registry", + "kubernetes-cluster", + "bare-metal-servers", + "game-server-api", + "anti-ddos-protection", + "anti-cheat-api", + ]; + + if (acceptedServices.includes(service)) return true; + + return false; +}; |
