This guide assumes you have a Cloudflare account and basic familiarity with Wrangler (Cloudflare’s CLI).
Architecture
Sher’s backend consists of:- Cloudflare Workers: Handles authentication, uploads, and serving preview links
- Cloudflare R2: Stores uploaded build files (S3-compatible object storage)
- KV Storage: Stores deployment metadata and user sessions
- GitHub OAuth: User authentication (optional)
- Polar: Billing integration for Pro subscriptions (optional)
Prerequisites
- Cloudflare account with Workers and R2 enabled
- Wrangler CLI installed
- GitHub OAuth App (optional, for authentication)
- Polar account (optional, for Pro subscriptions)
Step 1: Deploy the Worker
Clone and Install
First, navigate to the worker directory in the Sher repository:Authenticate with Cloudflare
Login to Cloudflare via Wrangler:Create R2 Bucket
Create an R2 bucket for storing uploaded files:Create KV Namespace
Create a KV namespace for storing metadata:wrangler.toml with the namespace ID:
Deploy the Worker
Deploy to Cloudflare:By default, your worker is deployed to a
workers.dev subdomain. You can add a custom domain later in the Cloudflare dashboard.Step 2: Set Up GitHub OAuth (Optional)
To enable user authentication, create a GitHub OAuth App.Create OAuth App
- Go to github.com/settings/developers
- Click “New OAuth App”
- Fill in the details:
- Application name: Sher (or your custom name)
- Homepage URL:
https://your-domain.workers.dev - Authorization callback URL:
https://your-domain.workers.dev/auth/callback
- Click “Register application”
Add Secrets to Worker
After creating the OAuth App, note the Client ID and Client Secret. Add them as secrets to your worker:Test Authentication
Test the login flow:Step 3: Configure Secrets
Sher requires a few environment variables for full functionality.Required Secrets (with GitHub OAuth)
Optional Secrets (for Polar billing)
If you want to enable Pro subscriptions via Polar:- POLAR_WEBHOOK_SECRET: Generated when you create a webhook in your Polar dashboard
- POLAR_ACCESS_TOKEN: Create an API token in Polar settings
- POLAR_PRO_PRODUCT_ID: The product ID for your Pro subscription (from Polar)
How to set up Polar billing
How to set up Polar billing
- Create a Polar account and set up your organization
- Create a product for “Sher Pro” priced at $8/month
- Note the product ID from the Polar dashboard
- Create an API token in Polar settings
- Create a webhook pointing to
https://your-domain.workers.dev/webhooks/polar - Add the secrets to your worker using
wrangler secret put
Step 4: Point the CLI at Your Instance
Configure the Sher CLI to use your self-hosted instance instead of the defaultsher.sh.
Set Environment Variable
Add to your shell configuration (~/.bashrc, ~/.zshrc, etc.):
Test Your Instance
Configuration Options
Custom Domain
To use a custom domain (e.g.,sher.yourdomain.com):
-
Add a CNAME record in your DNS provider pointing to your worker:
-
Add the custom domain in the Cloudflare dashboard:
- Go to Workers & Pages → Your worker → Settings → Domains
- Click “Add Custom Domain”
- Enter your domain and click “Add Domain”
-
Update your CLI configuration:
Adjusting Limits
You can customize rate limits and upload sizes by editing the worker code. Example from the worker source (these are the default values):Monitoring and Maintenance
View Logs
Stream real-time logs from your worker:Check Analytics
View usage analytics in the Cloudflare dashboard:- Go to Workers & Pages → Your worker
- Click on “Metrics” tab
- View requests, errors, and performance data
R2 Storage
Monitor R2 usage:R2 storage is very cost-effective. The first 10 GB/month is free, then $0.015/GB/month.
Troubleshooting
Authentication fails
Authentication fails
Ensure your GitHub OAuth callback URL matches exactly:Check that
GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET are set correctly:Uploads fail
Uploads fail
Verify your R2 bucket name matches the binding in Check R2 bucket permissions in the Cloudflare dashboard.
wrangler.toml:Rate limits not working
Rate limits not working
Ensure your KV namespace is correctly bound:The ID in
wrangler.toml must match your KV namespace ID.Custom domain not working
Custom domain not working
Verify DNS propagation:Ensure the CNAME points to your
workers.dev subdomain.Updating Your Instance
To update your self-hosted instance with the latest changes:Cost Estimate
Cloudflare’s pricing is very generous for self-hosting:| Service | Free Tier | Pricing |
|---|---|---|
| Workers | 100,000 requests/day | $0.50/million requests |
| R2 Storage | 10 GB/month | $0.015/GB/month |
| R2 Operations | Class A: 1M/month Class B: 10M/month | Class A: 0.36/million |
| KV Storage | 1 GB | $0.50/GB/month |
Security Considerations
- Secrets: Always use
wrangler secret put— never commit secrets to version control - OAuth: Keep your GitHub OAuth Client Secret secure
- Rate limiting: Implement IP-based rate limiting if needed
- CORS: Configure CORS headers appropriately for your domain
- Content validation: The worker validates file types and sizes
Next Steps
CLI Options
Learn about all CLI flags and options
Framework Support
See which frameworks are supported
Commands
Explore all available commands
Contributing
Contribute to Sher on GitHub