Deploy: Cloudflare Workers (repackager.sublimetext.io)
Overview
- This repo is a Cloudflare Worker (see
wrangler.toml,src/index.js). - GitHub Actions deploys on every push to
mainor via manual dispatch. - Custom domain mapping to
repackager.sublimetext.iois preconfigured inwrangler.tomlusingcustom_domain = true.
Prerequisites
- The
sublimetext.ioDNS zone is managed by Cloudflare (nameservers pointing to Cloudflare). - A Cloudflare account with permission to deploy Workers and manage routes on that zone.
- GitHub repo admin permissions to add repository secrets.
What gets created/used
- Worker name:
repackager(fromwrangler.toml). - No server/VPS is required. Cloudflare handles TLS, scaling, and routing.
- Custom domain mapping is declared in
wrangler.tomlviaroutes = [{ pattern = "repackager.sublimetext.io", custom_domain = true }]and is applied on deploy.
GitHub Actions setup
-
Repo already contains
.github/workflows/deploy.yml.- It installs dependencies and runs
npx wrangler deploy. - It reads the following secrets:
CLOUDFLARE_API_TOKENCLOUDFLARE_ACCOUNT_ID
- It installs dependencies and runs
-
Add GitHub secrets:
- In GitHub: Settings → Secrets and variables → Actions → New repository secret
- Add
CLOUDFLARE_API_TOKENwith the API token you create below. - Add
CLOUDFLARE_ACCOUNT_IDwith your Cloudflare Account ID.
Create a Cloudflare API token (least-privilege) Option A — Use the “Edit Cloudflare Workers” template (easiest)
- Cloudflare Dashboard → My Profile (top-right) → API Tokens → Create Token.
- Choose template: “Edit Cloudflare Workers”.
- Restrict to the specific Account (and optionally specific Zone) that holds
sublimetext.io. - Create and copy the token value; store it as the
CLOUDFLARE_API_TOKENGitHub secret.
Option B — Custom token (if you prefer explicit scopes)
- Cloudflare Dashboard → My Profile → API Tokens → Create Token → Create Custom Token.
- Scopes (minimum):
- Account → Workers Scripts: Edit
- Account → Workers Routes: Edit
- Zone → Zone: Read (limit to the
sublimetext.iozone)
- Resources: limit to the specific Account and the
sublimetext.ioZone. - Create and copy the token value; store it as the
CLOUDFLARE_API_TOKENGitHub secret.
Find your Cloudflare Account ID
- Cloudflare Dashboard → Select your account (left nav) → Overview.
- The Account ID appears on the right side of the Overview page (or under Workers & Pages → Overview).
- Copy this value into the
CLOUDFLARE_ACCOUNT_IDGitHub secret.
Custom domain: repackager.sublimetext.io
- Already configured in
wrangler.tomlas a custom domain and applied by CI on deploy. - Alternative (dashboard-only): Workers & Pages → select
repackager→ Triggers → Custom Domains → Addrepackager.sublimetext.io.
Do I need to set up DNS records?
- If
sublimetext.iois already on Cloudflare, no manual DNS records are needed. The custom domain wires traffic at the edge, and TLS certs are auto-provisioned. - If the domain is not on Cloudflare, move DNS to Cloudflare (change nameservers at your registrar) before using Workers custom domains.
Triggering a deploy
- Push to
main→ deploy runs automatically and applies the custom domain mapping fromwrangler.toml. - Or run manually: GitHub → Actions → Deploy Worker → Run workflow.
Local development and manual deploys
- Dev server:
npm run start(runswrangler dev). - Manual deploy:
npm run deployornpx wrangler deploy.- For local/manual deploys, authenticate wrangler once:
npx wrangler login(opens browser) - Or set the same env vars you use in CI (
CLOUDFLARE_API_TOKEN,CLOUDFLARE_ACCOUNT_ID).
- For local/manual deploys, authenticate wrangler once:
Notes about this Worker
- Caches responses at the edge using
caches.defaultwith long-lived cache headers. - Expects a
?url=pointing at a ZIP and optional?name=to name the resulting.sublime-package. - Security:
?url=must use HTTPS and match an allowlist of hosts defined inwrangler.tomlunder[vars].ALLOW_HOSTS. Default iscodeload.github.com, bitbucket.org, codelab.org, gitlab.com. - Size cap: upstream ZIPs larger than
MAX_ZIP_BYTES(default 25 MB) are rejected with HTTP 413.
Troubleshooting
- 403 during deploy: the API token is missing scopes (add Workers Scripts:Edit and Workers Routes:Edit) or is for the wrong account/zone.
- Route not applied: ensure you added either a Custom Domain (Dashboard) or a
routesentry inwrangler.tomland that the token has permission to edit routes. - Not served on the subdomain: confirm the
sublimetext.iozone is on Cloudflare (nameservers set) and that the custom domain/route exists and is active. - 400/403 at runtime: the provided
?url=is invalid, non-HTTPS, points to localhost/IP, or its hostname is not inALLOW_HOSTS. - 413 at runtime: the upstream ZIP exceeds
MAX_ZIP_BYTES.