// --- Global Banner API Cloudflare Worker --- // index.js (or src/index.js if using a build system) // ========================================================== // IMPORTANT CONFIGURATION VARIABLES // YOU MUST ENSURE THESE MATCH YOUR CLOUDFLARE SETUP! // ========================================================== // 1. ALLOWED_ORIGINS: // List all domains that will send API requests to this Worker. // Browser 'Origin' headers DO NOT include trailing slashes, so omit them here. const ALLOWED_ORIGINS = [ 'https://cme-modeler.pages.dev', // Your dev site 'https://spottheaurora.co.nz', // Your live site 'https://banner-control.pages.dev', // Your admin page hosted on Cloudflare Pages (or wherever admin.html is) 'https://banner-api.thenamesrock.workers.dev' // If your worker itself is an origin for requests ]; // ========================================================== // WORKER CODE STARTS HERE // ========================================================== // Validate secret binding at worker initialization time (deploy-time check) if (typeof BANNER_AUTH_TOKEN === 'undefined') { throw new Error('BANNER_AUTH_TOKEN secret is not defined. Please configure it in your Worker settings.'); } // Validate KV binding (basic check) if (typeof BANNER_DATA === 'undefined') { throw new Error('BANNER_DATA KV Namespace binding is not defined. Please configure it in your Worker settings.'); } // Content of your admin.html file (pasted directly into the worker script as a string) // IMPORTANT: The `value` for `apiUrl` here points to the worker's *public API endpoint*. const ADMIN_HTML_CONTENT = ` Global Banner Admin

🌌 Global Banner Admin

Worker API Configuration

This is the root endpoint of your banner Worker (e.g., `https://your-worker.your-domain.com`). The API paths (`/banner`, `/admin/banner`) will be appended automatically.

Warning: Keep this key secure! Do NOT share it publicly or commit it to Git.

Banner Content

The main text content of your global banner.

Select a predefined theme, or 'Custom' to use the color pickers.

Used if 'Custom' style is selected.

Used if 'Custom' style is selected.

Emojis displayed at the beginning of the message.

If checked, users can close the banner until the next page load.

The banner will automatically hide after this date and time (UTC).

Optional URL for a "Learn More" link within the banner.

Text for the optional link (e.g., "Details").

Live Preview

Banner preview will appear here.

This is how the banner will look on your main site. Emojis and exact gradients may vary slightly across devices/browsers.