This repository was archived by the owner on Mar 13, 2025. It is now read-only.
Commit 7d032ee
authored
[Miniflare 3] Add support for routing to multiple Workers (#520)
* Add support for routing to multiple Workers
This change ports Miniflare 2's `mounts` router to Miniflare 3. This
attempts to replicate the logic of the `route(s)` field in the
Wrangler configuration file:
https://developers.cloudflare.com/workers/platform/triggers/routes/#matching-behavior
Internally, this is implemented by binding all routable workers as
service bindings in the entry service. The first worker is always
bound as a "fallback", in case no routes match. Validation has been
added to ensure we a) have a fallback, b) don't have workers with
duplicate names that would cause bindings with the same name, and c)
all routable/fallback workers have code so they actually get added
as `workerd` services.
* Require code for all Workers
It doesn't really make sense to have Workers without code. This
change updates our `zod` schemas to encode this requirement.
* fixup! Add support for routing to multiple Workers
Assert names unique when collecting routes
* fixup! Add support for routing to multiple Workers
Move `CORE_PLUGIN_NAME` back to `core`
* fixup! Add support for routing to multiple Workers
Add specific error message when defining multiple unnamed workers
* fixup! Add support for routing to multiple Workers
Use `Map` when de-duping services
* fixup! Add support for routing to multiple Workers
Extract out common plugin/namespace/persist Worker into function
* fixup! Add support for routing to multiple Workers
Use same specificity calculation for routes as internal service
* fixup! fixup! Add support for routing to multiple Workers1 parent 4cb0dd9 commit 7d032ee
18 files changed
+715
-248
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
38 | 41 | | |
39 | 42 | | |
40 | 43 | | |
| |||
68 | 71 | | |
69 | 72 | | |
70 | 73 | | |
71 | | - | |
72 | | - | |
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | 80 | | |
86 | 81 | | |
87 | 82 | | |
| |||
100 | 95 | | |
101 | 96 | | |
102 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
103 | 101 | | |
104 | 102 | | |
105 | 103 | | |
| |||
109 | 107 | | |
110 | 108 | | |
111 | 109 | | |
112 | | - | |
113 | 110 | | |
114 | 111 | | |
115 | 112 | | |
116 | 113 | | |
117 | | - | |
| 114 | + | |
| 115 | + | |
118 | 116 | | |
119 | 117 | | |
120 | 118 | | |
121 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
122 | 135 | | |
123 | 136 | | |
124 | 137 | | |
| |||
150 | 163 | | |
151 | 164 | | |
152 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
153 | 181 | | |
154 | 182 | | |
155 | 183 | | |
| |||
622 | 650 | | |
623 | 651 | | |
624 | 652 | | |
625 | | - | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
626 | 671 | | |
627 | 672 | | |
628 | 673 | | |
| |||
633 | 678 | | |
634 | 679 | | |
635 | 680 | | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | 681 | | |
642 | 682 | | |
643 | 683 | | |
644 | 684 | | |
645 | 685 | | |
646 | 686 | | |
647 | 687 | | |
| 688 | + | |
| 689 | + | |
648 | 690 | | |
649 | 691 | | |
650 | 692 | | |
| |||
661 | 703 | | |
662 | 704 | | |
663 | 705 | | |
| 706 | + | |
| 707 | + | |
664 | 708 | | |
665 | | - | |
666 | 709 | | |
667 | 710 | | |
668 | 711 | | |
669 | 712 | | |
670 | 713 | | |
671 | | - | |
672 | 714 | | |
673 | 715 | | |
674 | 716 | | |
675 | 717 | | |
676 | | - | |
677 | | - | |
678 | | - | |
| 718 | + | |
| 719 | + | |
679 | 720 | | |
680 | 721 | | |
681 | 722 | | |
682 | 723 | | |
683 | 724 | | |
684 | 725 | | |
685 | | - | |
| 726 | + | |
686 | 727 | | |
687 | 728 | | |
688 | 729 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | 2 | | |
5 | 3 | | |
6 | 4 | | |
| |||
9 | 7 | | |
10 | 8 | | |
11 | 9 | | |
| 10 | + | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
| |||
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | 72 | | |
77 | 73 | | |
78 | 74 | | |
| |||
87 | 83 | | |
88 | 84 | | |
89 | 85 | | |
90 | | - | |
| 86 | + | |
91 | 87 | | |
92 | | - | |
| 88 | + | |
93 | 89 | | |
94 | 90 | | |
95 | 91 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | 45 | | |
52 | 46 | | |
53 | 47 | | |
| |||
80 | 74 | | |
81 | 75 | | |
82 | 76 | | |
83 | | - | |
| 77 | + | |
| 78 | + | |
84 | 79 | | |
85 | 80 | | |
86 | 81 | | |
| |||
106 | 101 | | |
107 | 102 | | |
108 | 103 | | |
| 104 | + | |
| 105 | + | |
109 | 106 | | |
110 | 107 | | |
111 | 108 | | |
| |||
120 | 117 | | |
121 | 118 | | |
122 | 119 | | |
123 | | - | |
| 120 | + | |
124 | 121 | | |
125 | 122 | | |
126 | 123 | | |
| |||
139 | 136 | | |
140 | 137 | | |
141 | 138 | | |
142 | | - | |
| 139 | + | |
143 | 140 | | |
144 | 141 | | |
145 | 142 | | |
| |||
0 commit comments