index.ts
This file
Path
examples/durable-objects/src/index.ts
26 lines · 531 bytes · TypeScript
Last changed by
chore: tweak (#75)Yusuke Wadabefore adoption223429f
History of this fileTake it
refactor: refactor something (#65)Yusuke Wadabefore adoption336afc8
lines 1–12why, one step back1import { Hono } from '../../../src/index'23export { Counter } from './counter'45declare module '../../../src/index' {6 interface Env {7 COUNTER: DurableObjectNamespace8 }9}1011const app = new Hono()12chore: tweak (#75)Yusuke Wadabefore adoption223429f
line 13why, one step back13app.get('*', async (c) => {refactor: refactor something (#65)Yusuke Wadabefore adoption336afc8
lines 14–17why, one step back14 const id = c.env.COUNTER.idFromName('A')15 const obj = c.env.COUNTER.get(id)16 const resp = await obj.fetch(c.req.url)17chore: tweak (#75)Yusuke Wadabefore adoption223429f
line 18why, one step back18 if (resp.status === 404) {refactor: refactor something (#65)Yusuke Wadabefore adoption336afc8
lines 19–25why, one step back19 return c.text('404 Not Found', 404)20 }2122 const count = parseInt(await resp.text())23 return c.text(`Count is ${count}`)24})25chore: tweak (#75)Yusuke Wadabefore adoption223429f
line 26why, one step back26export default app