Kind: Function
Source: src/adapter/bun/server.ts
Part of: Adapter
Get Bun Server Object from Context
getBunServer reads the Bun Server instance from a request context created by the Bun adapter. Use it inside route handlers when server-level Bun APIs are needed alongside normal Hono context methods.
Signature
tsfunction getBunServer(c: Context): T | undefined
Parameters
| Name | Type |
|---|---|
c | Context |
Returns: T | undefined
Diagram
mermaidgraph LR BunServer[Bun Server] --> BunAdapter[Bun adapter serve()] BunAdapter --> Context[Hono Context] Context --> GetServer[getBunServer] GetServer --> ServerApi[Bun Server APIs]
Usage
tsimport { Hono } from 'hono'
import { getBunServer, serve } from 'hono/bun'
const app = new Hono()
app.get('/server', (c) => {
const server = getBunServer(c)
return c.json({
hostname: server.hostname,
port: server.port,
})
})
serve({
fetch: app.fetch,
})
AI Coding Instructions
- Call
getBunServer(c)from handlers that receive a HonoContext. - Run the application through the Bun adapter so the active server is available on the context.
- Keep Bun-specific server operations in Bun adapter routes or modules.
- Do not use this function in handlers shared with non-Bun adapters.
Used by
2 references from 2 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.
Imported by (2)
getConnInfo—src/adapter/bun/conninfo.ts:10BunServerWebSocket—src/adapter/bun/websocket.ts:8
Was this page helpful?