Skip to content

Commit

Permalink
fix(pages): syntax error in example (cloudflare#2762)
Browse files Browse the repository at this point in the history
* s/req/request

This snipped generates an error when run because there's no object called `req`. This PR fixes the reference.

* Fix code snippet for _worker.js

Co-authored-by: Ashcon Partovi <[email protected]>
  • Loading branch information
threepointone and Electroid authored Nov 22, 2021
1 parent 1f0a95c commit 7a76926
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions products/pages/src/content/platform/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,14 @@ filename: _worker.js
---
export default {
async fetch(request, env) {
if (req.url.startsWith('/api/')) {
// TODO: Custom /api/* Worker logic
return new Response('TODO: add logic')
const url = new URL(request.url);
if (url.pathname.startsWith('/api/')) {
// TODO: Add your custom /api/* logic here.
return new Response('Ok');
}

// Otherwise, serve static asset(s).
// Without this, Worker will error and no assets will be served.
return env.ASSETS.fetch(request)
// Otherwise, serve the static assets.
// Without this, the Worker will error and no assets will be served.
return env.ASSETS.fetch(request);
}
}
```
Expand Down

0 comments on commit 7a76926

Please sign in to comment.