Friday, August 8, 2025

“Building Civic Infrastructure with Serverless APIs and Region-Aware Routing” Ideal for remixers, journalists, and technologists exploring public-facing deployments.

Hashtag Rotator Service – Civic README

πŸ“‘ hashtag-rotator-service

Modular serverless microservice for rotating region-aware hashtags, logging GitHub events, and powering public dashboards. Ideal for civic technologists, journalists, and remixers.

πŸ› ️ API Endpoints • πŸ” Cron Scheduling • 🌍 Geo Routing • πŸ“‘ Webhook Logging • πŸ§ͺ Diagnostics • 🧩 Remixable Infrastructure

🧠 About This Project

This project fetches real-time trending hashtags from Trends24 and serves them via region-specific API endpoints. It includes scheduled cron tasks, GitHub webhook logging, and geo-aware routing — all deployed seamlessly on Vercel.

  • πŸ›️ Civic dashboards
  • πŸ“° Media headline rotators
  • 🧩 Remixable region-aware tools

πŸ› ️ Features

CapabilityDetails
πŸ’¬ API Endpoints/api/trends, /api/cron, /api/github-webhook, /api/diagnostics, /api/index, /api/hashtag-rotator-service
⏰ Cron SchedulingVercel triggers /api/cron daily at 10:00 UTC (1PM Nairobi)
πŸ“‘ GitHub WebhookVerifies HMAC signature and logs events to /api/diagnostics
🌍 Geo RoutingKenya visitors rerouted to /kenya-trends using IP headers
πŸ§ͺ Diagnostics API/api/diagnostics returns delivery logs, verification status, and timestamps
πŸ›‘️ Crash ProtectionAll handlers use try/catch blocks for resilience
πŸ” Testing Scripttest.sh validates endpoint response and logs headers

πŸš€ Quick Start Guide

git clone https://github.com/pmmutiti/hashtag-rotator-service.git
cd hashtag-rotator-service

This project includes a preconfigured vercel.json file for instant deployment.

🧾 Deployment Config

This file defines build targets, scheduled tasks, and geo-aware rewrites for Vercel deployment. It ensures modular routing, public observability, and remixable behavior across all endpoints.

πŸ”§ Build Targets

"builds": [
  { "src": "api/cron.js", "use": "@vercel/node" },
  { "src": "api/trends.js", "use": "@vercel/node" },
  { "src": "api/github-webhook.js", "use": "@vercel/node" },
  { "src": "api/diagnostics.js", "use": "@vercel/node" },
  { "src": "api/index.js", "use": "@vercel/node" },
  { "src": "api/hashtag-rotator-service.js", "use": "@vercel/node" }
]

⏰ Cron Job

"crons": [
  {
    "path": "/api/cron",
    "schedule": "0 10 * * *"
  }
]

🌍 Geo-Aware Rewrites

"rewrites": [
  {
    "source": "/kenya-trends",
    "has": [
      {
        "type": "header",
        "key": "x-vercel-ip-country",
        "value": "KE"
      }
    ],
    "destination": "/api/trends?region=kenya"
  },
  {
    "source": "/kenya-trends",
    "destination": "/api/trends?region=global"
  },
  {
    "source": "/trends/:region",
    "destination": "/api/trends?region=:region"
  }
]

πŸ“ File Structure

hashtag-rotator-service/
├── api/
│   ├── cron.js
│   ├── trends.js
│   ├── github-webhook.js
│   ├── diagnostics.js
│   ├── index.js
│   └── hashtag-rotator-service.js
├── test.sh
├── README.md
├── civic-preview.html
├── vercel.json

πŸ§ͺ Validation Tools

Use test.sh to manually confirm that endpoints like /api/webhook respond correctly.

If payload snapshots are growing under diagnostics/webhook-payloads, your webhook is live.

🧩 Remix Notes

“Civic infrastructure should be transparent and traceable.”

This repo is designed for

No comments:

Post a Comment

πŸ“Š The immortal Executive Dashboard That Gives You "God" Level Visibility: From Data Overload to Clarity: How This Dashboard Simplifies Your Decisions

Executive Dashboard | HealthTrend Cognitive Platform 🧠 HEALTHTREND COGNITIVE ...