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
123456789101112131415161718192021222324252627import { Hono } from '../../../src/index'
export { Counter } from './counter'
declare module '../../../src/index' { interface Env { COUNTER: DurableObjectNamespace }}
const app = new Hono()
app.get('*', async (c) => { const id = c.env.COUNTER.idFromName('A') const obj = c.env.COUNTER.get(id) const resp = await obj.fetch(c.req.url)
if (resp.status === 404) { return c.text('404 Not Found', 404) }
const count = parseInt(await resp.text()) return c.text(`Count is ${count}`)})
export default app