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 fileTake it
Support module workers syntax for Cloudflare Workers (#43)Yusuke Wadabefore adoptionfceed74
lines 1–3why, one step back1import { Hono } from '../../../src/index'2import type { Env } from '../../../src/index'3Fixed durable objects example (#46)Yusuke Wadabefore adoptiona22a0eb
lines 4–5why, one step back4export { Counter } from './counter'5Support module workers syntax for Cloudflare Workers (#43)Yusuke Wadabefore adoptionfceed74
lines 6–17why, one step back6declare 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 back1819 if(resp.status === 404) {20 return c.text('404 Not Found', 404)21 }22Support module workers syntax for Cloudflare Workers (#43)Yusuke Wadabefore adoptionfceed74
lines 23–31why, one step back23 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}