flow
flow
CDCloudflare Developers
Created by flow on 4/26/2024 in #workers-help
Service pattern with Hono.js
Hey Im coming from Expressjs backend dev background, and its a bit confusing to me how to implement service pattern with Hono js on top of Cloudflare workers. What i want to achieve is create a singleton object of thirdparty SDK service in /services/engine.ts file.
const engine = new Engine(env.ENGINE_API_KEY)
const engine = new Engine(env.ENGINE_API_KEY)
And then inside hono routes use it like this:
const app = new Hono()
app.get(async c => {
const res = await engine.get("foo")
return c.json(res)
})
const app = new Hono()
app.get(async c => {
const res = await engine.get("foo")
return c.json(res)
})
How can I achieve this? Im getting error inside engine.ts file, since it cannot access env vars for some reason.
28 replies