2024-06-02 17:14:11 +02:00
|
|
|
import { upgradeWebSocket } from '../../src/adapter/cloudflare-workers'
|
2024-09-12 05:05:41 +02:00
|
|
|
import { env, getRuntimeKey } from '../../src/helper/adapter'
|
2023-05-02 14:16:17 +02:00
|
|
|
import { Hono } from '../../src/hono'
|
2023-03-06 13:12:22 +01:00
|
|
|
|
|
|
|
const app = new Hono()
|
|
|
|
|
2024-06-02 15:49:40 +02:00
|
|
|
app.get('/', (c) => c.text(`Hello from ${getRuntimeKey()}`))
|
2023-03-06 13:12:22 +01:00
|
|
|
|
|
|
|
app.get('/env', (c) => {
|
|
|
|
const { NAME } = env<{ NAME: string }>(c)
|
|
|
|
return c.text(NAME)
|
|
|
|
})
|
|
|
|
|
2024-06-02 17:14:11 +02:00
|
|
|
app.get(
|
|
|
|
'/ws',
|
|
|
|
upgradeWebSocket(() => {
|
|
|
|
return {
|
|
|
|
onMessage(event, ws) {
|
|
|
|
ws.send(event.data as string)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2023-03-06 13:12:22 +01:00
|
|
|
export default app
|