Skip to content
Myr

index.ts

This file

Path

example/durable-objects/src/index.ts

31 lines · 679 bytes · TypeScript

Last changed by

Fixed durable objects example (#46)Yusuke Wadabefore adoptiona22a0eb

History of this file

Take it

Support module workers syntax for Cloudflare Workers (#43)Yusuke Wadabefore adoptionfceed74

lines 1–3why, one step back
1import { Hono } from '../../../src/index'
2import type { Env } from '../../../src/index'3

Fixed durable objects example (#46)Yusuke Wadabefore adoptiona22a0eb

lines 4–5why, one step back
4export { Counter } from './counter'
5

Support module workers syntax for Cloudflare Workers (#43)Yusuke Wadabefore adoptionfceed74

lines 6–17why, one step back
6declare module '../../../src/index' {
7 interface Env {8 COUNTER: DurableObjectNamespace9 }10}1112const app = new Hono()1314app.get('*', async c => {15 const id = c.env.COUNTER.idFromName('A')16 const obj = c.env.COUNTER.get(id)17 const resp = await obj.fetch(c.req.url)

Fixed durable objects example (#46)Yusuke Wadabefore adoptiona22a0eb

lines 18–22why, one step back
18
19 if(resp.status === 404) {20 return c.text('404 Not Found', 404)21 }22

Support module workers syntax for Cloudflare Workers (#43)Yusuke Wadabefore adoptionfceed74

lines 23–31why, one step back
23 const count = parseInt(await resp.text())
24 return c.text(`Count is ${count}`)25})2627export default {28 fetch(request: Request, env: Env, event: FetchEvent) {29 return app.fetch(request, env, event)30 },31}