Skip to content

Commit

Permalink
multi-worker fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
RamIdeas committed Sep 24, 2024
1 parent 0792fa0 commit e2c3e53
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fixtures/multi-worker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# multi-worker

The aim of this fixture is to use `wrangler dev` for multiple workers in the same project.

## Usage

```sh
npx wrangler dev --x-dev-env \
-c packages/worker-a/wrangler.toml \
-c packages/worker-b/wrangler.toml
```
7 changes: 7 additions & 0 deletions fixtures/multi-worker/packages/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "multi-worker",
"workspaces": [
"worker-a",
"worker-b"
]
}
15 changes: 15 additions & 0 deletions fixtures/multi-worker/packages/worker-a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "worker-a",
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"start": "wrangler dev --x-dev-env"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240909.0",
"wrangler": "workspace:*"
},
"volta": {
"extends": "../../package.json"
}
}
21 changes: 21 additions & 0 deletions fixtures/multi-worker/packages/worker-a/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default {
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext
): Promise<Response> {
const result = await env.WORKER_B.hello();

return new Response(
`Worker A called Worker B: ${result}`
);
},
};





export interface Env {
WORKER_B: { hello(): Promise<string> };
}
13 changes: 13 additions & 0 deletions fixtures/multi-worker/packages/worker-a/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es2021",
"lib": ["es2021"],
"module": "es2022",
"types": ["@cloudflare/workers-types/experimental"],
"noEmit": true,
"isolatedModules": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
7 changes: 7 additions & 0 deletions fixtures/multi-worker/packages/worker-a/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name = "worker-a"
main = "src/index.ts"
compatibility_date = "2024-09-22"

services = [
{ binding = "WORKER_B", service = "worker-b", entrypoint = "default" }
]
15 changes: 15 additions & 0 deletions fixtures/multi-worker/packages/worker-b/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "worker-b",
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"start": "wrangler dev --x-dev-env"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240909.0",
"wrangler": "workspace:*"
},
"volta": {
"extends": "../../package.json"
}
}
7 changes: 7 additions & 0 deletions fixtures/multi-worker/packages/worker-b/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { WorkerEntrypoint } from "cloudflare:workers";

export default class extends WorkerEntrypoint {
async hello() {
return "Hello World from Worker B!";
}
}
13 changes: 13 additions & 0 deletions fixtures/multi-worker/packages/worker-b/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es2021",
"lib": ["es2021"],
"module": "es2022",
"types": ["@cloudflare/workers-types/experimental"],
"noEmit": true,
"isolatedModules": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
5 changes: 5 additions & 0 deletions fixtures/multi-worker/packages/worker-b/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "worker-b"
main = "src/index.ts"
compatibility_date = "2024-09-22"

dev.port = 8788

0 comments on commit e2c3e53

Please sign in to comment.