feat(landing): show animated live demo stats counters

Add a "Live from the demo instance" section to the landing page that
fetches feeds_created and emails_received from the demo /api/stats and
counts them up on scroll into view. Make /api/stats publicly readable
(CORS *) and refresh the stale allowlist origins to kill-the.news.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Julien Herr
2026-05-23 10:09:13 +02:00
parent d1959acad1
commit fd6a1a945f
3 changed files with 98 additions and 6 deletions
+13 -4
View File
@@ -12,11 +12,11 @@ function req(path: string, init: RequestInit = {}): Request {
describe("CORS middleware", () => {
it("adds CORS headers for an allowed origin", async () => {
const res = await worker.fetch(
req("/rss/some-feed", { headers: { Origin: "https://getmynews.app" } }),
req("/rss/some-feed", { headers: { Origin: "https://kill-the.news" } }),
env as unknown as Env,
);
expect(res.headers.get("Access-Control-Allow-Origin")).toBe(
"https://getmynews.app",
"https://kill-the.news",
);
});
@@ -33,7 +33,7 @@ describe("CORS middleware", () => {
req("/rss/some-feed", {
method: "OPTIONS",
headers: {
Origin: "https://getmynews.app",
Origin: "https://kill-the.news",
"Access-Control-Request-Method": "GET",
},
}),
@@ -41,7 +41,16 @@ describe("CORS middleware", () => {
);
expect(res.status).toBe(204);
expect(res.headers.get("Access-Control-Allow-Origin")).toBe(
"https://getmynews.app",
"https://kill-the.news",
);
});
it("makes /api/stats readable from any origin", async () => {
const res = await worker.fetch(
req("/api/stats", { headers: { Origin: "https://example.com" } }),
env as unknown as Env,
);
expect(res.status).toBe(200);
expect(res.headers.get("Access-Control-Allow-Origin")).toBe("*");
});
});
+3 -2
View File
@@ -22,7 +22,7 @@ import { FORWARD_EMAIL_IPS_CACHE_TTL_MS } from "./config/constants";
type AppEnv = { Bindings: Env };
const ALLOWED_ORIGINS = ["https://getmynews.app", "https://www.getmynews.app"];
const ALLOWED_ORIGINS = ["https://kill-the.news", "https://www.kill-the.news"];
// Fallback ForwardEmail.net IP addresses in case API fetch fails
const FALLBACK_FORWARD_EMAIL_IPS = [
@@ -140,7 +140,8 @@ api.use("/inbound", async (c, next) => {
// API routes (inbound webhook)
api.post("/inbound", handleInbound);
// Public monitoring stats (JSON)
// Public monitoring stats (JSON) — readable from any origin (landing page, embeds)
api.use("/stats", cors({ origin: "*" }));
api.get("/stats", handleStats);
// RSS feed routes (public)