Skip to content
Myr

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 file

Take it

refactor: refactor something (#65)Yusuke Wadabefore adoption336afc8

lines 1–12why, one step back
1import { Hono } from '../../../src/index'
23export { Counter } from './counter'45declare module '../../../src/index' {6 interface Env {7 COUNTER: DurableObjectNamespace8 }9}1011const app = new Hono()12

chore: tweak (#75)Yusuke Wadabefore adoption223429f

line 13why, one step back
13app.get('*', async (c) => {

refactor: refactor something (#65)Yusuke Wadabefore adoption336afc8

lines 14–17why, one step back
14 const id = c.env.COUNTER.idFromName('A')
15 const obj = c.env.COUNTER.get(id)16 const resp = await obj.fetch(c.req.url)17

chore: tweak (#75)Yusuke Wadabefore adoption223429f

line 18why, one step back
18 if (resp.status === 404) {

refactor: refactor something (#65)Yusuke Wadabefore adoption336afc8

lines 19–25why, one step back
19 return c.text('404 Not Found', 404)
20 }2122 const count = parseInt(await resp.text())23 return c.text(`Count is ${count}`)24})25

chore: tweak (#75)Yusuke Wadabefore adoption223429f

line 26why, one step back
26export default app