Skip to content
File

Blob: samples/extensions/worker.js

javascript25 lines
1// Copyright (c) 2023 Cloudflare, Inc.
2// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3// https://opensource.org/licenses/Apache-2.0
4 
5import { BurritoShop } from "burrito-shop:burrito-shop";
6 
7export default {
8 async fetch(req, env) {
9 const burritoType = await req.text();
10 
11 if (req.headers.has("X-Use-Direct-Api")) {
12 // extensions can decide to provide direct API access to users
13 const shop = new BurritoShop({
14 "meat": ["rice", "meat", "beans", "cheese", "salsa"],
15 "veggie": ["rice", "guacamole", "beans", "salsa"],
16 });
17 return new Response(shop.makeBurrito(burritoType).price());
18 } else {
19 // or can be used to define wrapped bindings,
20 // which is more in line with capability-based design
21 return new Response(env.shop.makeBurrito(burritoType).price());
22 }
23 }
24};