yusukebe
yusukebe
CDCloudflare Developers
Created by Ping for toast on 5/23/2024 in #workers-help
[VERY EXTREMELY CURSED] How can I access process.env (at start time)
You can try this syntax:
app.use('/auth/*', async (c, next) => {
const mw = jwt({
secret: c.env.JWT_SECRET
})
return await mw(c, next)
})
app.use('/auth/*', async (c, next) => {
const mw = jwt({
secret: c.env.JWT_SECRET
})
return await mw(c, next)
})
79 replies
CDCloudflare Developers
Created by flow on 4/26/2024 in #workers-help
Service pattern with Hono.js
Sorry for confusing! new Hono() is called once outside the fetch() as you mentioned. But the middleware that is defined in the factory is called everytime:
app.use((c) => {
const client = initClient(c.env.TOKEN)
c.set('client', client)
})
app.use((c) => {
const client = initClient(c.env.TOKEN)
c.set('client', client)
})
So you are right!
28 replies
CDCloudflare Developers
Created by flow on 4/26/2024 in #workers-help
Service pattern with Hono.js
As a syntax, one app would cover every route as you imagine. But, actually, the app will be created per request.
28 replies
CDCloudflare Developers
Created by flow on 4/26/2024 in #workers-help
Service pattern with Hono.js
Hi @flow Indeed, you have to create the engine instance per route in the Cloudflare environment. Then, you can use a simple factory method to do it like the following:
import { Hono } from 'hono'

type Env = {
Bindings: {
TOKEN: string
}
Variables: {
client: Client
}
}

export const createAppWithDB = () => {
const app = new Hono<Env>()
app.use((c) => {
const client = initClient(c.env.TOKEN)
c.set('client', client)
})
return app
}
import { Hono } from 'hono'

type Env = {
Bindings: {
TOKEN: string
}
Variables: {
client: Client
}
}

export const createAppWithDB = () => {
const app = new Hono<Env>()
app.use((c) => {
const client = initClient(c.env.TOKEN)
c.set('client', client)
})
return app
}
Then you can use it in your routes:
const app = createAppWithDB()

app.post('/api', (c) => {
c.var.client.put(/* */)
// ...
})
const app = createAppWithDB()

app.post('/api', (c) => {
c.var.client.put(/* */)
// ...
})
28 replies
CDCloudflare Developers
Created by Firu on 2/5/2024 in #workers-discussions
is Hono a good alternative to itty-
Sorry, missed your message, I think the Windows issue has been fixed with this PR. https://github.com/honojs/honox/pull/116
16 replies
CDCloudflare Developers
Created by Firu on 2/5/2024 in #workers-discussions
is Hono a good alternative to itty-
Hi Kevin. You are right. It may only be for marketing purposes. The time for non-router matters is a big factor. And most simple apps are usually faster enough on the edge.
16 replies
CDCloudflare Developers
Created by Firu on 2/5/2024 in #workers-discussions
is Hono a good alternative to itty-
Hi. Tomorrow v4 will be released and new examples will be available, so you'll see how to use Tailwind CSS there.
16 replies
CDCloudflare Developers
Created by Firu on 2/5/2024 in #workers-discussions
is Hono a good alternative to itty-
Thanks. Once loaded into memory, the Hono router is the fastest of all JavaScript routers, including the itty router. But, on Cloudflare Workers, memory is cleared after a time. Bootups are better if the file size is small, so it may be better to use simple apps with less access
16 replies
CDCloudflare Developers
Created by Firu on 2/5/2024 in #workers-discussions
is Hono a good alternative to itty-
Hi. Can I see the benchmark results?
16 replies