You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/workers/vite-plugin/tutorial.mdx
+17-6Lines changed: 17 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -147,12 +147,8 @@ The `main` field specifies the entry file for your Worker code.
147
147
### Add your API Worker
148
148
149
149
```ts title="worker/index.ts"
150
-
interfaceEnv {
151
-
ASSETS:Fetcher;
152
-
}
153
-
154
150
exportdefault {
155
-
fetch(request, env) {
151
+
fetch(request) {
156
152
const url =newURL(request.url);
157
153
158
154
if (url.pathname.startsWith("/api/")) {
@@ -163,7 +159,7 @@ export default {
163
159
164
160
returnnewResponse(null, { status: 404 });
165
161
},
166
-
} satisfiesExportedHandler<Env>;
162
+
} satisfiesExportedHandler;
167
163
```
168
164
169
165
The Worker above will be invoked for any non-navigation request that does not match a static asset.
@@ -172,6 +168,21 @@ It returns a JSON response if the `pathname` starts with `/api/` and otherwise r
172
168
:::note
173
169
For top-level navigation requests, browsers send a `Sec-Fetch-Mode: navigate` header.
174
170
If this is present and the URL does not match a static asset, the `not_found_handling` behavior will be invoked rather than the Worker.
171
+
This implicit routing is the default behavior.
172
+
173
+
If you would instead like to define the routes that invoke your Worker explicitly, you can provide an array of route patterns to [`run_worker_first`](/workers/static-assets/binding/#run_worker_first).
174
+
This opts out of interpreting the `Sec-Fetch-Mode` header.
0 commit comments