# Renewonomics — Netlify Deployment Guide ## What you're deploying | File | Purpose | |---|---| | `*.html` | Static frontend pages | | `ads.txt` | AdSense authorised seller file | | `netlify.toml` | Build config + cron schedule | | `package.json` | Declares `@netlify/blobs` dependency | | `netlify/functions/fetch-feeds.mjs` | **Scheduled function** — runs every 30 min, fetches RSS, writes to Blobs | | `netlify/functions/api.mjs` | **REST API** — all frontend read/write operations | | `netlify/functions/lib/rss-parser.mjs` | Shared RSS parsing utility | | `netlify/functions/lib/store.mjs` | Netlify Blobs wrapper | --- ## Step 1 — Push to GitHub ```bash git init git add . git commit -m "Initial Renewonomics deploy" git remote add origin https://github.com/YOUR_USERNAME/renewonomics.git git push -u origin main ``` --- ## Step 2 — Connect to Netlify 1. Go to [app.netlify.com](https://app.netlify.com) → **Add new site** → **Import from Git** 2. Choose GitHub and select your `renewonomics` repo 3. Build settings are detected from `netlify.toml` automatically: - **Publish directory:** `.` (repo root) - **Build command:** *(leave blank — no build step needed)* 4. Click **Deploy site** --- ## Step 3 — Set Environment Variables In Netlify dashboard → **Site** → **Environment variables**, add: | Variable | Value | Notes | |---|---|---| | `RW_ADMIN_KEY` | A strong random string, e.g. `rw_k8x2mPqL9vNdR5wE` | The secret key protecting all admin API writes. Generate one at [randomkeygen.com](https://randomkeygen.com) | | `SUPER_ADMIN_EMAIL` | `esraigroup@gmail.com` | The super admin email for bootstrap key delivery | | `ADMIN_EMAILS` | Comma-separated list of other admin emails | Optional — e.g. `other@example.com,another@example.com` | > **Important:** After adding env vars, trigger a redeploy from **Deploys** → **Trigger deploy**. --- ## Step 4 — Verify the scheduled function 1. Go to **Functions** tab in Netlify dashboard 2. You should see `fetch-feeds` listed with a clock icon (scheduled) 3. It will first run within 30 minutes of deploy 4. You can also trigger it manually: **Functions** → `fetch-feeds` → **Invoke** --- ## Step 5 — Add your first RSS feed 1. Visit `https://your-site.netlify.app/admin.html` 2. Log in with `esraigroup@gmail.com` + any password 3. Go to **Feed Manager** → **+ Add RSS Feed** 4. Add a feed (e.g. `https://electrek.co/feed/`) and click **Save** 5. Click **↻ Fetch All Now** — this calls `POST /api/admin/feeds/fetch` 6. Visit `https://your-site.netlify.app/feed.html` — articles appear From this point, `fetch-feeds` runs every 30 minutes automatically. --- ## Step 6 — Custom domain (optional) 1. Netlify dashboard → **Domain management** → **Add custom domain** 2. Follow the DNS instructions (add a CNAME or A record) 3. HTTPS is provisioned automatically via Let's Encrypt --- ## How the data flows ``` Every 30 min (cron) │ ▼ fetch-feeds.mjs ←── reads feed config from Netlify Blobs │ ├── fetches each RSS URL server-side (no CORS issues) │ ├── deduplicates against stored articles │ └── writes merged articles → Netlify Blobs │ ┌───────────────────────┤ │ │ ▼ ▼ feed.html admin.html GET /api/articles GET /api/admin/feeds (reads from Blobs) POST /api/admin/feeds/fetch ``` --- ## Local development ```bash npm install npm install -g netlify-cli netlify dev ``` `netlify dev` starts a local server at `http://localhost:8888` with: - All HTML files served from root - Functions available at `/.netlify/functions/` - Environment variables loaded from `.env` file or your linked Netlify site Create a `.env` file for local dev: ``` RW_ADMIN_KEY=local_dev_key_change_me SUPER_ADMIN_EMAIL=esraigroup@gmail.com ``` > **Never commit `.env` to git.** Add it to `.gitignore`. --- ## Troubleshooting **Admin panel shows "No admin key" warning:** - Check `RW_ADMIN_KEY` is set in Netlify environment variables - Trigger a redeploy after setting env vars - Check browser console for the bootstrap fetch response **Feeds not updating automatically:** - Check **Functions** tab — `fetch-feeds` should show recent invocations - If schedule isn't firing, verify `netlify.toml` has `schedule = "*/30 * * * *"` under `[functions."fetch-feeds"]` - Netlify free tier includes 125,000 function invocations/month; at 48/day you use ~1,440/month **Articles not appearing in feed.html:** - Open browser DevTools → Network tab → check `/.netlify/functions/api/articles` response - If 500 error, check Functions logs in Netlify dashboard **CORS errors in browser:** - Verify the `[[headers]]` block in `netlify.toml` is present - Check that `Access-Control-Allow-Origin: *` appears in response headers