Docket Upload Worker Setup
This Cloudflare Worker enables PR-based docket uploads from the /docket/submit/ form.
Prerequisites
- A Cloudflare account with Workers enabled
- A GitHub Personal Access Token (PAT) with
reposcope
Setup Steps
1. Create GitHub Personal Access Token
- Go to GitHub Settings > Developer settings > Personal access tokens > Tokens (classic)
- Click “Generate new token (classic)”
- Give it a descriptive name: “FaithFrontier Docket Worker”
- Select scopes:
repo(Full control of private repositories)
- Generate and save the token securely
2. Deploy Worker to Cloudflare
- Install Wrangler CLI:
npm install -g wrangler - Login to Cloudflare:
wrangler login - Create a new worker:
cd worker wrangler init docket-upload -
Copy the
worker.jscontent to your worker script - Configure the worker:
- Create
wrangler.toml:name = "docket-upload" main = "worker.js" compatibility_date = "2024-01-01" [env.production] vars = { REPO_OWNER = "XTX33", REPO_NAME = "FaithFrontier" }
- Create
- Add the GitHub token as a secret:
wrangler secret put GITHUB_PATWhen prompted, paste your GitHub token
- Deploy:
wrangler deploy - Note the worker URL (e.g.,
https://docket-upload.your-subdomain.workers.dev)
3. Update the Submit Form
Edit /assets/js/docket-submit.js and replace the placeholder URL with your worker URL:
const workerUrl = 'https://docket-upload.your-subdomain.workers.dev/docket-upload';
4. Configure CORS (if needed)
If your worker URL is different from faithfrontier.org, update the CORS origin in worker.js:
'Access-Control-Allow-Origin': 'https://faithfrontier.org',
How It Works
- User fills out the form at
/docket/submit/ - JavaScript sends PDF + metadata to Cloudflare Worker
- Worker creates a new git branch
- Worker uploads PDF to
cases/<slug>/filings/ - Worker updates
_data/docket/<slug>.ymlwith new entry - Worker creates a Pull Request for review
- You review and merge the PR
Security
- The GitHub token only has
reposcope (read/write repository access) - Token is stored as a Cloudflare secret (encrypted at rest)
- CORS restricts requests to faithfrontier.org
- All uploads go through PR review before merging
Alternative: Manual Upload
If you prefer not to use the worker, you can manually:
- Upload PDFs to the correct folder:
cases/<slug>/filings/ - Edit
_data/docket/<slug>.ymlto add the entry - Commit and push, or create a PR
Troubleshooting
- CORS errors: Check the
Access-Control-Allow-Originheader in worker.js - 401 errors: Verify the GitHub token is valid and has correct scopes
- 404 errors: Ensure repository name and owner are correct
- Worker not found: Check the worker URL in docket-submit.js
Testing
Test the worker locally:
wrangler dev
Then update docket-submit.js temporarily to use http://localhost:8787 for testing.