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
1234567891011121314151617181920212223242526272829303132import { Hono } from '../../../src/index'import type { Env } 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 { fetch(request: Request, env: Env, event: FetchEvent) { return app.fetch(request, env, event) },}