π‘ 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.
π§ 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
| Capability | Details |
|---|---|
| π¬ API Endpoints | /api/trends, /api/cron, /api/github-webhook, /api/diagnostics, /api/index, /api/hashtag-rotator-service |
| ⏰ Cron Scheduling | Vercel triggers /api/cron daily at 10:00 UTC (1PM Nairobi) |
| π‘ GitHub Webhook | Verifies HMAC signature and logs events to /api/diagnostics |
| π Geo Routing | Kenya visitors rerouted to /kenya-trends using IP headers |
| π§ͺ Diagnostics API | /api/diagnostics returns delivery logs, verification status, and timestamps |
| π‘️ Crash Protection | All handlers use try/catch blocks for resilience |
| π Testing Script | test.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
π§ 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.
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