commit d1fcbd5233d416e631cc7136b15ae41a1622b4a8
parent d3967594c99177a2fbadf31b7a4abe271aafc96b
Author: William Lindholm <85635561+LindholmLabs@users.noreply.github.com>
Date: Thu, 24 Sep 2026 15:22:43 +0000
Implemented simple on page load status checks
Diffstat:
3 files changed, 46 insertions(+), 37 deletions(-)
diff --git a/status-bot/.env.example b/status-bot/.env.example
@@ -0,0 +1 @@
+URLS="https://git.lindholmlabs.com, https://cloud.lindholmlabs.com"
+\ No newline at end of file
diff --git a/status-bot/src/index.js b/status-bot/src/index.js
@@ -1,15 +1,46 @@
-/**
- * Welcome to Cloudflare Workers! This is your first worker.
- *
- * - Run `npm run dev` in your terminal to start a development server
- * - Open a browser tab at http://localhost:8787/ to see your worker in action
- * - Run `npm run deploy` to publish your worker
- *
- * Learn more at https://developers.cloudflare.com/workers/
- */
+
export default {
- async fetch(request, env, ctx) {
- return new Response("Hello World!");
- },
+ async fetch(request) {
+ const urls = parseUrlsFromEnv();
+ const now = new Date();
+ let output = "";
+
+ for (const url of urls) {
+ output += `<tr><td>${url}</td><td>${await(responseIsOk(url))}</td></tr>`
+ }
+
+ const html = `<!DOCTYPE html>
+ <body>
+ <h1>STATUS</h1>
+ <table>
+ <tr>
+ <td>Source</td>
+ <td>Status</td>
+ </tr>
+ ${output}
+ </table>
+ <p>Last updated: ${now.toISOString()}</p>
+ </body>`;
+
+ return new Response(html, {
+ headers: {
+ "content-type": "text/html;charset=UTF-8",
+ },
+ });
+ },
};
+
+function parseUrlsFromEnv() {
+ const urls = process.env.URLS || "";
+ return urls.split(",");
+}
+
+async function responseIsOk(url) {
+ try {
+ const response = await fetch(url);
+ return "<span style='color:green;'>online</span>";
+ } catch {
+ return "<span style='color:red;'>offline</span>";
+ }
+}
+\ No newline at end of file
diff --git a/status-bot/test/index.spec.js b/status-bot/test/index.spec.js
@@ -1,25 +0,0 @@
-import {
- env,
- createExecutionContext,
- waitOnExecutionContext,
- SELF,
-} from "cloudflare:test";
-import { describe, it, expect } from "vitest";
-import worker from "../src";
-
-describe("Hello World worker", () => {
- it("responds with Hello World! (unit style)", async () => {
- const request = new Request("http://example.com");
- // Create an empty context to pass to `worker.fetch()`.
- const ctx = createExecutionContext();
- const response = await worker.fetch(request, env, ctx);
- // Wait for all `Promise`s passed to `ctx.waitUntil()` to settle before running test assertions
- await waitOnExecutionContext(ctx);
- expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
- });
-
- it("responds with Hello World! (integration style)", async () => {
- const response = await SELF.fetch("http://example.com");
- expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
- });
-});