feat: Add Cloudflare Workers support#4714
Open
biplavbarua wants to merge 1 commit into
Open
Conversation
|
@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. |
|
How do you set the environment variables? |
Author
|
Hi @clover-yan, thanks for the review! In Cloudflare Workers, environment variables and secrets are passed into the To ensure compatibility with the existing codebase (which relies on // 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 For configuration:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cloudflare Workers Support
Description
This PR enables
github-readme-statsto 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
src/common/adapter.js): Translates standard Request/Response objects to the Express-stylereq/resexpected by existing handlers.src/worker.js): Handles routing and dispatches requests to the card generators using the adapter.wrangler.toml): Configuration for Cloudflare deployment, using thenodejs_compatcompatibility flag.gist.jsandwakatime.jsto use standard ES imports for JSON, replacingcreateRequireto support modern bundling.Verification
wrangler dev(port 8787)./apiworks and invokes the stats fetcher (returning error SVG when tokens are missing, which proves execution path).How to Test
npm installnpm install -D wrangler(if not present)npx wrangler devhttp://localhost:8787/api?username=anuraghazraCloses # (if applicable)