Kevin
Kevin
CDCloudflare Developers
Created by PneuTueur on 8/9/2024 in #workers-help
Access D1 database outside a request
Bindings are just passed along automatically in the 2nd/env argument to handlers/middleware, if you wired things up manually, you'll need to feed it in yourself, but if you just use the default fetch signature, it'll pick up all the cloudflare args and pass them along (env and context).
import { Router } from 'itty-router'

const router = Router()

router.get('/', (request, env, ctx) => {
// we have access to the request, env/bindings, and context
}

// MANUAL
export default {
fetch: (request, env, ctx) => router.fetch(request, env, ctx)
}

// AUTOMAGIC (same effect as above)
export default router

// or if on a version of wrangler that throws a "middleware" error, just export the deconstructed router like this
export default { ...router }
import { Router } from 'itty-router'

const router = Router()

router.get('/', (request, env, ctx) => {
// we have access to the request, env/bindings, and context
}

// MANUAL
export default {
fetch: (request, env, ctx) => router.fetch(request, env, ctx)
}

// AUTOMAGIC (same effect as above)
export default router

// or if on a version of wrangler that throws a "middleware" error, just export the deconstructed router like this
export default { ...router }
Basically, itty (platform agnostic) allows you to pass anything throughout the entire handler/middleware chain just by passing it to the router.fetch function after the Request object. Cloudflare calls the { fetch } function with these args, so you automatically see them in itty handlers!
18 replies
CDCloudflare Developers
Created by Shannor on 8/12/2024 in #workers-help
How to use a worker to download an image into R2
@Shannor, @James get you sorted on the fetch firing?
8 replies
CDCloudflare Developers
Created by Kevin on 6/21/2024 in #wrangler
Hey wrangler team... this is a crosspost
It would not be… in order to pass CI off to GitHub, I need it outside the workers environment… I guess I can create a mock and reroute to that for tests somehow…
3 replies
CDCloudflare Developers
Created by Kevin on 6/20/2024 in #durable-objects
So I'm getting ready to publish
bump
2 replies
CDCloudflare Developers
Created by Kevin on 6/20/2024 in #durable-objects
So I'm getting ready to publish
No description
2 replies
CDCloudflare Developers
Created by Kevin on 6/11/2024 in #durable-objects
Kevin Whitley (@kevinrwhitley) on X
BTW - itty-durable@next is available for play-testing as of a few minutes ago! Rough API docs with examples included in README. https://x.com/ittydev/status/1800952641620451621
6 replies
CDCloudflare Developers
Created by Kevin on 6/11/2024 in #durable-objects
Kevin Whitley (@kevinrwhitley) on X
This can at least get that back to your Worker or whatever called the RPC method... baby steps!
6 replies
CDCloudflare Developers
Created by Kevin on 6/11/2024 in #durable-objects
Kevin Whitley (@kevinrwhitley) on X
That would certainly be a trick, wouldn't it? 🙂
6 replies
CDCloudflare Developers
Created by Kevin on 6/11/2024 in #durable-objects
Kevin Whitley (@kevinrwhitley) on X
Absolutely will be documenting the full lifecycle of how it works. Luckily, while there's a bit of Proxy dark-arts (like with most itty libs) to make it work, the entire source is super tiny, so it's very easy to explain - including a line-by-line "what's happening".
6 replies