Skip to content

feat: Add Cloudflare Workers support#4714

Open
biplavbarua wants to merge 1 commit into
anuraghazra:masterfrom
biplavbarua:master
Open

feat: Add Cloudflare Workers support#4714
biplavbarua wants to merge 1 commit into
anuraghazra:masterfrom
biplavbarua:master

Conversation

@biplavbarua

Copy link
Copy Markdown

Cloudflare Workers Support

Description

This PR enables github-readme-stats to be deployed on Cloudflare Workers.

This is a strategic addition to address the "Deployment Paused" issues caused by Vercel's free tier limits. Cloudflare Workers provides 100,000 requests/day on its free tier, offering a robust alternative for the community.

Changes

  • New Adapter Layer (src/common/adapter.js): Translates standard Request/Response objects to the Express-style req/res expected by existing handlers.
  • Worker Entry Point (src/worker.js): Handles routing and dispatches requests to the card generators using the adapter.
  • Wrangler Config (wrangler.toml): Configuration for Cloudflare deployment, using the nodejs_compat compatibility flag.
  • JSON Imports: Updated gist.js and wakatime.js to use standard ES imports for JSON, replacing createRequire to support modern bundling.

Verification

  • Verified locally using wrangler dev (port 8787).
  • Confirmed that routing to /api works and invokes the stats fetcher (returning error SVG when tokens are missing, which proves execution path).
  • Existing tests passed.

How to Test

  1. npm install
  2. npm install -D wrangler (if not present)
  3. npx wrangler dev
  4. Access http://localhost:8787/api?username=anuraghazra

Closes # (if applicable)

@vercel

vercel Bot commented Dec 25, 2025

Copy link
Copy Markdown

@biplavbarua is attempting to deploy a commit to the github readme stats Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added wakatime-card Issues related to the wakatime card. dependencies Pull requests that update a dependency file gist-card labels Dec 25, 2025
@clover-yan

Copy link
Copy Markdown

How do you set the environment variables?

@biplavbarua

Copy link
Copy Markdown
Author

Hi @clover-yan, thanks for the review!

In Cloudflare Workers, environment variables and secrets are passed into the fetch handler via the env parameter.

To ensure compatibility with the existing codebase (which relies on process.env), I've added a shim in src/worker.js:

// src/worker.js
export default {
  async fetch(request, env, ctx) {
    // Polyfill process.env for the application
    globalThis.process = globalThis.process || {};
    globalThis.process.env = { ...globalThis.process.env, ...env };
    
    // ... rest of the handler
  }
}

This allows us to access variables like PAT_1 using standard process.env.PAT_1 calls throughout the rest of the application.

For configuration:

  • Non-sensitive vars: Can be set in wrangler.toml under [vars].
    • Secrets (like PATs): Should be set via the Cloudflare Dashboard or using wrangler secret put PAT_1.

@BBleae

BBleae commented Feb 28, 2026

Copy link
Copy Markdown

Follow-up is now available in #4823 (contains this branch + commit 727d211). I couldn't push to this PR head branch due permission limits, so I opened #4823 as a replacement for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file gist-card wakatime-card Issues related to the wakatime card.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants