Skip to content

getBunServer

reference
1 min readUpdated

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

ts
function getBunServer(c: Context): T | undefined

Parameters

NameType
cContext

Returns: T | undefined

Diagram

mermaid
graph LR
  BunServer[Bun Server] --> BunAdapter[Bun adapter serve()]
  BunAdapter --> Context[Hono Context]
  Context --> GetServer[getBunServer]
  GetServer --> ServerApi[Bun Server APIs]

Usage

ts
import { 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 Hono Context.
  • 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)

  • getConnInfosrc/adapter/bun/conninfo.ts:10
  • BunServerWebSocketsrc/adapter/bun/websocket.ts:8

Was this page helpful?

Download as PDF
getBunServer — Hono (narrator proof)