🧭 System Summary

  • Single Cloudflare Worker (worker.js) handles all requests for pub.ihnyc-rc.org
  • Static files served from ./public via Cloudflare’s Assets binding with SPA-style fallback (unknown paths β†’ index.html)
  • /api/events can query up to three Notion databases and assembles a unified JSON payload
  • API responses cached at the edge for 2 minutes (CACHE_TTL_SECONDS = 120)
  • No build step; plain HTML/CSS/JS for all static pages

Sources: worker.js, wrangler.toml


🧩 Request Routing

flowchart TD
  REQ["Incoming Request"] --> WORKER["Cloudflare Worker (worker.js)"]
  WORKER --> IS_API{"/api/events?"}

  IS_API -- Yes --> CACHE_HIT{Edge Cache Hit?}
  CACHE_HIT -- Yes --> CACHED["Return Cached Response"]
  CACHE_HIT -- No --> NOTION["Query Notion APIs"]
  NOTION --> ASSEMBLE["Assemble JSON payload"]
  ASSEMBLE --> STORE["Store in edge cache (2 min TTL)"]
  STORE --> RETURN_API["Return JSON"]

  IS_API -- No --> ASSETS["Cloudflare Assets (./public)"]
  ASSETS --> FOUND{Asset found?}
  FOUND -- Yes --> SERVE["Serve static file"]
  FOUND -- No --> FALLBACK["Serve index.html (SPA fallback)"]

Sources: worker.js (fetch handler, CACHING section)


πŸ—„οΈ Notion Databases

Env VarPurposeRequired
NOTION_DATABASE_IDPub events β€” today’s events and this week’s eventsYes (for live data)
NOTION_SHIFTS_DATABASE_IDPub tender shifts, operational timeframes, last-call configNo
NOTION_ANNOUNCEMENTS_DATABASE_IDScrolling announcements shown on TV displayNo
  • NOTION_DATABASE_ID is required when live Notion data is enabled
  • If NOTION_API_KEY is absent, the worker skips live Notion queries and returns placeholder data
  • NOTION_API_KEY is required (set as a Wrangler secret, never in wrangler.toml)

Sources: worker.js (CONFIG section), wrangler.toml


πŸ“¦ /api/events Payload Assembly

When /api/events is called, the worker:

  1. Determines β€œtoday” using the normal calendar date in America/New_York (see what-counts-as-today)
  2. Queries the Events DB for todayEvents using a broad date window, then narrows it to rows whose local Eastern start date equals todayISO
  3. Queries the Events DB again for weekEvents covering calendar tomorrow through calendar day +7
  4. Queries the Announcements DB for TV-included announcements (if configured)
  5. Queries the Shifts DB for the currently active shift and on-duty pub tender (if configured)
  6. Assembles pub hours for the week from the Shifts DB (if configured)
  7. Returns a unified JSON object (see api)

Sources: worker.js (handleEventsApi, fetchFromNotion, fetchPubTenderFromNotion)


⚑ Caching

  • Cache TTL: 2 minutes (CACHE_TTL_SECONDS = 120)
  • Cache key: full request URL
  • Cache stored in Cloudflare’s edge cache (not KV or D1)
  • TV display client independently soft-refreshes every 2 minutes
  • Hard <meta http-equiv="refresh" content="300"> fallback every 5 minutes in case JS hangs
  • Overnight serving-hours state on / and /tv/ is computed against America/New_York, not the device timezone, so post-midnight active shifts stay attached to their original shift day

Sources: worker.js (CACHING section), public/tv/index.html, public/tv/script.js (startRefreshCountdown)


πŸ—οΈ Static Site Structure

public/
β”œβ”€β”€ index.html               # Landing page (pub hours widget, navigation)
β”œβ”€β”€ styles.css               # Global styles (Jost + Playfair Display)
β”œβ”€β”€ assets/                  # Logos and images
β”‚   β”œβ”€β”€ I-House_Emblem_Regular_RGB_Green.svg   # Primary I-House logo / favicon
β”‚   β”œβ”€β”€ RC-transparent-background-logo.png     # RC classification badge logo
β”‚   β”œβ”€β”€ avi_logo_bg.png                        # AVI Foodsystems logo
β”‚   └── affectivetech_logo_bg_trans_logoonly.png  # Affective Tech footer logo
β”œβ”€β”€ tv/                      # TV signage display (primary feature)
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ styles.css
β”‚   └── script.js
β”œβ”€β”€ left-light-av-panel/     # AV/lighting control panel
β”œβ”€β”€ menu/                    # Placeholder pages
β”œβ”€β”€ events/
β”œβ”€β”€ announcements/
β”œβ”€β”€ pub-tenders/
β”œβ”€β”€ resources/
└── tutorials/

Sources: public/ directory, wrangler.toml ([assets] binding)