Skip to content

Remove Cloudflare Worker, use client-side GitHub API#6

Closed
jonathanpopham wants to merge 1 commit intomainfrom
feat/no-worker
Closed

Remove Cloudflare Worker, use client-side GitHub API#6
jonathanpopham wants to merge 1 commit intomainfrom
feat/no-worker

Conversation

@jonathanpopham
Copy link
Contributor

@jonathanpopham jonathanpopham commented Mar 2, 2026

Summary

  • Removes the Cloudflare Worker dependency — no external infrastructure needed
  • Frontend JS calls GitHub API directly using a fine-grained PAT (injected at build time)
  • Static skeleton loading page generated at /generating/?repo=name
  • .gitignore added to exclude site/ build artifacts

Setup required

  1. Create a fine-grained PAT scoped to issues:write on this repo
  2. Add it as ISSUES_TOKEN repo secret

Test plan

  • Verify go run generate-index.go generates site/generating/index.html
  • Verify Generate button creates a GitHub issue via API
  • Verify skeleton page loads and polls for real docs

Summary by CodeRabbit

Release Notes

  • New Features

    • Added skeleton loading page displayed during site generation
    • Implemented GitHub API token-based authentication for repository request submissions
  • Refactor

    • Consolidated application architecture by integrating worker functionality into main application
  • Chores

    • Updated build workflow configuration and repository ignore settings

Replace the Cloudflare Worker proxy with direct GitHub API calls
from the browser using a fine-grained PAT (issues:write scope).
The token is injected at build time via ISSUES_TOKEN env var.

- Delete worker/ directory (index.js, wrangler.toml)
- Generate static skeleton page at /generating/?repo=name
- Frontend JS calls GitHub API directly to create issues
- build-index.yml passes ISSUES_TOKEN secret to generator
- Add .gitignore to exclude site/ build artifacts
@coderabbitai
Copy link

coderabbitai bot commented Mar 2, 2026

Walkthrough

This PR migrates the repository request submission architecture from a Cloudflare Worker proxy to a direct Go backend approach. The ISSUES_TOKEN is now injected into templates and the skeleton loading page is generated server-side via a new generateSkeleton() function instead of being served by the removed Worker. The Worker infrastructure is completely removed.

Changes

Cohort / File(s) Summary
Workflow & Build Configuration
.github/workflows/build-index.yml, worker/wrangler.toml, .gitignore
Added ISSUES_TOKEN to workflow environment; removed Cloudflare Worker configuration; added site/ directory to gitignore.
Go Backend Logic
generate-index.go
Added generateSkeleton() function to create skeleton loading page; introduced PageData struct to pass token and config to templates; updated index generation to pass ISSUES_TOKEN to client-side JavaScript; modified client-side logic to authenticate directly with GitHub API for issue creation and redirect to skeleton page.
Worker Removal
worker/index.js
Completely removed Cloudflare Worker implementation including fetch handler, POST /api/request routing, skeleton page serving, JSON response utilities, and skeleton HTML template.

Sequence Diagram

sequenceDiagram
    actor User
    participant Client as Browser (Client JS)
    participant Backend as Go Backend
    participant GitHubAPI as GitHub API

    User->>Client: Load index page
    Client->>Backend: GET /
    Backend->>Client: Render index template<br/>(inject GH_TOKEN, GH_REPO)
    
    User->>Client: Submit repo URL form
    Client->>GitHubAPI: POST /repos/[GH_REPO]/issues<br/>(Bearer GH_TOKEN)
    GitHubAPI->>Client: Issue created (success)
    Client->>Backend: Navigate to /generating/?repo=name
    
    Backend->>Client: Serve skeleton page<br/>(via generateSkeleton)
    Client->>Client: Display loading UI<br/>(poll for docs page)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

A Worker once stood at the gate,
Now Go takes the reins—what a fate! 💫
Tokens flow straight to GitHub's API,
Skeletons build as users wait... ✨
No proxy, no edge—just backend ballet! 🎭

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Remove Cloudflare Worker, use client-side GitHub API' directly and accurately describes the main architectural change in the PR: removing the worker infrastructure and shifting to browser-based API calls.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/no-worker

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@generate-index.go`:
- Around line 114-117: The PageData struct currently includes a Token field and
the code injects ISSUES_TOKEN into rendered HTML (exposing the secret); remove
Token from PageData and stop passing ISSUES_TOKEN into any client-side
templates/JS (references: PageData, ISSUES_TOKEN, and the template rendering in
generate-index.go), then implement a server-side relay endpoint that performs
authenticated GitHub issue creation (or switch to a GitHub App/OAuth flow) so
client JS calls your backend route instead of using the token directly; update
client-side calls (those currently sending the token) to call the new relay
endpoint and remove any code that reads/forwards ISSUES_TOKEN to the browser.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 21776a3 and b6dc419.

📒 Files selected for processing (5)
  • .github/workflows/build-index.yml
  • .gitignore
  • generate-index.go
  • worker/index.js
  • worker/wrangler.toml
💤 Files with no reviewable changes (2)
  • worker/wrangler.toml
  • worker/index.js

Comment on lines +114 to +117
type PageData struct {
Config
Token string
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: ISSUES_TOKEN is being published to every browser.

Line 153 injects the secret into the HTML, and Lines 539/611 send it from client-side JS. On a static site this is fully exposed (view-source/devtools), so anyone can spam or abuse issue creation on your repo.

Use a server-side relay (or GitHub App flow) so the credential never leaves trusted infrastructure.

🔒 Minimal safe mitigation (disable public token exposure)
 type PageData struct {
 	Config
-	Token string
 }

@@
-	return tmpl.Execute(f, PageData{Config: cfg, Token: os.Getenv("ISSUES_TOKEN")})
+	return tmpl.Execute(f, PageData{Config: cfg})
@@
-    var GH_TOKEN = '{{.Token}}';
+    var GH_TOKEN = '';

Also applies to: 153-153, 539-541, 608-613

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@generate-index.go` around lines 114 - 117, The PageData struct currently
includes a Token field and the code injects ISSUES_TOKEN into rendered HTML
(exposing the secret); remove Token from PageData and stop passing ISSUES_TOKEN
into any client-side templates/JS (references: PageData, ISSUES_TOKEN, and the
template rendering in generate-index.go), then implement a server-side relay
endpoint that performs authenticated GitHub issue creation (or switch to a
GitHub App/OAuth flow) so client JS calls your backend route instead of using
the token directly; update client-side calls (those currently sending the token)
to call the new relay endpoint and remove any code that reads/forwards
ISSUES_TOKEN to the browser.

@jonathanpopham
Copy link
Contributor Author

Closing — rethinking the approach from scratch.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant