This repository has two parts:
- Worker API (
src/index.js): Cloudflare Worker that returns SVG badges showing whethergithub.com/<username>.gpgcontains a real armored key. Supports styles, labels, and card theme. - Demo UI (
demo/): Vite + React + Tailwind app that previews badges and generates embed URLs/Markdown. Deploy to Vercel (recommended) or GitHub Pages.
The production instance is deployed at https://gpg-badge.hesreallyhim.workers.dev (and any custom domain configured there). You can self-host or deploy your own instance as described below.
Prereqs: Node 20+, Cloudflare account, Wrangler.
- Install deps (root):
npm install - Auth:
npx wrangler login - (Optional) Custom domain: add to
wrangler.tomlEnsure the DNS record is proxied (orange cloud) in Cloudflare.routes = [ { pattern = "gpg.yourdomain.com/*", zone_name = "yourdomain.com" } ]
- Deploy:
npm run deploy - Badge host is
https://gpg-badge.<your-account>.workers.devor your custom domain.
Behavior: On cache miss, the Worker fetches https://github.com/<username>.gpg, detects a real armored key (ignores GitHub’s “no key uploaded” placeholder), and returns an SVG. Headers: X-GPG-Status (available/none), X-Cache (HIT/MISS). Cache: 1h edge/browser, stale-while-revalidate 24h.
The demo calls the Worker host set in demo/src/App.jsx (generateUrl base).
- Vercel (recommended):
- In
demo/:npm run buildto verify. - Vercel import: Root Directory
demo, FrameworkVite, Buildnpm run build, Outputdist. - CLI (optional, from
demo/):npm run deploy:previewornpm run deploy:prod(requiresvercelinstalled). - Assign custom domain in Vercel if desired.
- In
- GitHub Pages (alternative):
- In
demo/vite.config.jssetbaseto/<repo-name>/. - Workflow:
cd demo && npm ci && npm run build, publishdemo/distto Pages.
- In
- Worker:
npm run dev(root, Cloudflare dev server at http://localhost:8787). - Demo:
cd demo && npm run dev(Vite dev server). PointgenerateUrlto your Worker host or a mock during local testing.
Badge SVG generators live in src/badges.js. Static SVG examples are generated to src/badges/ for editor preview.
After changing badge code:
- Run
npm run generate:badgesto regenerate static SVGs - Commit both the code changes and updated SVGs
The test and deploy scripts run check:badges which fails if the static SVGs don't match the generators. This prevents deploying with stale examples.
- Keep
wranglercurrent (npm install -D wrangler@latest). - Demo uses Tailwind 4.x with the
@tailwindcss/viteplugin; Vite config uses base/for Vercel. Adjust base if targeting Pages. - Encourage contributors to publish their GPG keys and adopt the badge in READMEs.