-
Notifications
You must be signed in to change notification settings - Fork 724
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "multi-worker", | ||
"workspaces": [ | ||
"worker-a", | ||
"worker-b" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |