Sensible defaults, advanced configuration.
Workertown is a collection of packages for building edge-runtime architectures.
You can check out the docs here.
npx wrangler init feature-flags && cd ./feature-flags
npm i @workertown/feature-flags
// src/worker.ts
import { featureFlags } from "@workertown/feature-flags";
export default featureFlags();
// wrangler.toml
name = "feature-flags"
main = "src/worker.ts"
compatibility_date = "2023-05-30"
workers_dev = false
route = { pattern = "flags.example.com/*", zone_name = "example.com" }
[vars]
FLAGS_API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
[[kv_namespaces]]
binding = "FLAGS_CACHE"
id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
preview_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
[[d1_databases]]
binding = "FLAGS_DB"
database_name = "feature-flags"
database_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
preview_database_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
npx wrangler publish
npx wrangler init files && cd ./files
npm i @workertown/files
// src/worker.ts
import { files } from "@workertown/files";
export default files();
// wrangler.toml
name = "files"
main = "src/worker.ts"
compatibility_date = "2023-05-30"
workers_dev = false
route = { pattern = "files.example.com/*", zone_name = "example.com" }
[vars]
FILES_API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
[[d1_databases]]
binding = "FILES_DB"
database_name = "files"
database_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
preview_database_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
[[r2_buckets]]
binding = "FILES_FILES"
bucket_name = "files"
preview_bucket_name = "files"
npx wrangler init kv && cd ./kv
npm i @workertown/kv
// src/worker.ts
import { kv } from "@workertown/kv";
export default kv();
// wrangler.toml
name = "kv"
main = "src/worker.ts"
compatibility_date = "2023-05-30"
workers_dev = false
route = { pattern = "kv.example.com/*", zone_name = "example.com" }
[vars]
KV_API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
[[kv_namespaces]]
binding = "KV_DB"
id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
preview_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
npx wrangler publish
npx wrangler init pub-sub && cd ./pub-sub
npm i @workertown/pub-sub
// src/worker.ts
import { pubSub } from "@workertown/pub-sub";
export default pubSub();
// wrangler.toml
name = "pub-sub"
main = "src/worker.ts"
compatibility_date = "2023-05-30"
workers_dev = false
route = { pattern = "pubsub.example.com/*", zone_name = "example.com" }
[vars]
PUBSUB_API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
[[d1_databases]]
binding = "PUBSUB_DB"
database_name = "pub-sub"
database_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
preview_database_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
[[queues.producers]]
queue = "pub-sub"
binding = "PUBSUB_QUEUE"
[[queues.consumers]]
queue = "pub-sub"
max_batch_size = 100
max_batch_timeout = 30
max_concurrency = 10
npx wrangler publish
npx wrangler init search && cd ./search
npm i @workertown/search
// src/worker.ts
import { search } from "@workertown/search";
export default search();
// wrangler.toml
name = "search"
main = "src/worker.ts"
compatibility_date = "2023-05-30"
workers_dev = false
route = { pattern = "search.example.com/*", zone_name = "example.com" }
[vars]
SEARCH_API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
[[kv_namespaces]]
binding = "SEARCH_CACHE"
id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
preview_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
[[d1_databases]]
binding = "SEARCH_DB"
database_name = "search"
database_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
preview_database_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
npx wrangler publish