{"id":25470391,"url":"https://github.com/msisdev/cf-worker-starter","last_synced_at":"2025-11-04T18:30:35.922Z","repository":{"id":238053218,"uuid":"795772540","full_name":"msisdev/cf-worker-starter","owner":"msisdev","description":"A template for cloudflare worker","archived":false,"fork":false,"pushed_at":"2024-06-17T10:36:16.000Z","size":91,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-24T15:28:27.573Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/msisdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-04T02:47:01.000Z","updated_at":"2024-06-17T10:36:19.000Z","dependencies_parsed_at":"2024-06-17T11:56:10.371Z","dependency_job_id":"184b6345-07f6-4395-aefc-c38935d35bd5","html_url":"https://github.com/msisdev/cf-worker-starter","commit_stats":null,"previous_names":["boxcolli/cf-worker-starter","msisdev/cf-worker-starter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msisdev%2Fcf-worker-starter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msisdev%2Fcf-worker-starter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msisdev%2Fcf-worker-starter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msisdev%2Fcf-worker-starter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/msisdev","download_url":"https://codeload.github.com/msisdev/cf-worker-starter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239437822,"owners_count":19638569,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-18T08:33:50.832Z","updated_at":"2025-11-04T18:30:35.871Z","avatar_url":"https://github.com/msisdev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cf-worker-starter\n\nA simple opinionated template for cloudflare worker project.\nFeel free to copy \u0026 modify.\n\n## How to use\n1. Download\n  ```\n  $ gh repo clone boxcolli/cf-worker-starter\n  $ npm i\n  ```\n\n2. Update gitignore list (those are written as comment initially):\n- `.dev.vars`\n- `.env.vitest`\n\n## Demo\n- https://cf-worker-demo.boxcolli.com\n- https://cf-worker-demo.boxcolli.com/v1/hello\n- https://cf-worker-demo.boxcolli.com/v1/hello/John\n\n## Notes\n\n### Staging\n\nThere are two environments: default and 'pro'. Each time you add an element in `wrangler.toml`, you should configure both, like below:\n```toml\n# /wrangler.toml\n...\n\n[vars]\nWHICH_ENV = \"dev\"\n\n[env.pro.vars]\nWHICH_ENV = \"pro\"\n```\n\nIf you want to deploy, you run `$ npm run deploy`, which actually is:\n```json\n// package.json\n{\n    \"scripts\": {\n      \"deploy\": \"wrangler deploy -e pro\",\n  },\n}\n```\n\nAbout `Secrets`, configure:\n- `.dev.vars` file for development\n  - `$ npx wrangler types` will detect it as well.\n- `$ npx wrangler secret put \u003cKEY\u003e -e pro` for production.\n\n### CORS\n\nI made two same router instances to deal with different stages. And they are statically configured. It won't affect the performance too much, probably.\n```ts\n// /src/router.ts\n...\n\nexport default {\n    dev: getRouter('*'),\n    pro: getRouter('https://some.domain')\n}\n```\n\n### Vitest\nSince `@cloudflare/vitest-pool-workers` [cannot run test remotely](https://developers.cloudflare.com/workers/testing/vitest-integration/get-started/), I adopted just `vitest`. So you should `$ npm run dev` before `$ npm run test`.\n\nI put an env file to detect the local test url.\n```\n// /.env.vitest\nLOCAL_URL=\"http://localhost:8787\"\n```\n\nThis value is loaded dynamically with `vitest.setup.ts`.\n```ts\n// /vitest.setup.ts\nexport interface Config {\n    LOCAL_URL: string\n}\n\nconst envFile = './.env.vitest'\ndotenv.config({ path: envFile })\n```\n\nSo I recommend you to put `.env.vitest` into gitignore list and modify it freely.\n\n### Dependencies\n```json\n{\n  \"devDependencies\": {\n    \"@cloudflare/workers-types\": \"^4.20240502.0\",\n    \"dotenv\": \"^16.4.5\",\n    \"typescript\": \"^5.0.4\",\n    \"vitest\": \"1.3.0\",\n    \"wrangler\": \"^3.0.0\"\n  },\n  \"dependencies\": {\n    \"http-status-codes\": \"^2.3.0\",\n    \"itty-router\": \"^5.0.17\",\n    \"pino\": \"^9.0.0\"\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsisdev%2Fcf-worker-starter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmsisdev%2Fcf-worker-starter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsisdev%2Fcf-worker-starter/lists"}