Skip to content

LLM Resources

backan/utils - Utility Exports โ€‹

These are helpful utilities and middleware functions provided by backan for building web applications faster with Hono.

๐Ÿ“„ List of Utilities โ€‹

๐ŸŒ Swagger UI โ€‹

  • swaggerUI โ†’ Serve interactive API docs.
ts
import { swaggerUI } from 'backan/utils'
app.route('/docs', swaggerUI({ url: '/openapi.json' }))

๐Ÿ” JWT & JWK โ€‹

  • jwt, jwk โ†’ Handle JWT auth and keys.
ts
import { jwt } from 'backan/utils'
app.use('/secure/*', jwt({ secret: 'my-secret' }))

๐Ÿง Cookies โ€‹

  • getCookie, setCookie, deleteCookie, getSignedCookie, setSignedCookie โ†’ Work with cookies.
ts
import { getCookie, setCookie } from 'backan/utils'

app.get('/', (c) => {
  const user = getCookie(c, 'user')
  if (!user) setCookie(c, 'user', 'guest')
  return c.text(`Hello ${user || 'new user'}`)
})

๐Ÿ“ฆ Cache & Compression โ€‹

  • cache
  • compress โ†’ Control caching and compression.
ts
app.use('*', compress())
app.use('/static/*', cache({ cacheName: 'static' }))

๐Ÿง  Context Storage โ€‹

  • contextStorage, getContext โ†’ Store and retrieve context across async calls.

๐Ÿ”„ Trailing Slash โ€‹

  • appendTrailingSlash, trimTrailingSlash โ†’ Normalize URLs.

๐ŸŒ CORS โ€‹

  • cors โ†’ Enable Cross-Origin Resource Sharing.
ts
app.use(cors())

๐Ÿ•ต๏ธ Secure Headers โ€‹

  • secureHeaders โ†’ Add common security headers.

โ›” IP Restriction โ€‹

  • ipRestriction โ†’ Restrict access by IP.

๐Ÿ•‘ Timeout & Body Limit โ€‹

  • timeout, bodyLimit โ†’ Request timeouts and body size limits.

๐Ÿงน Pretty JSON โ€‹

  • prettyJSON โ†’ Pretty-print JSON in dev.

๐Ÿ”„ Method Override โ€‹

  • methodOverride โ†’ Allow _method to override HTTP methods.

๐Ÿง  Combine โ€‹

  • some, every, except โ†’ Combine route conditions or logic.

๐Ÿงพ Accepts โ€‹

  • accepts โ†’ Handle content negotiation.

๐Ÿงผ Powered By โ€‹

  • poweredBy โ†’ Add X-Powered-By header.

๐Ÿงผ Logger โ€‹

  • logger โ†’ Request logging.

๐ŸŒ Language Detection โ€‹

  • languageDetector โ†’ Detect preferred language from headers.

โš ๏ธ HTTP Exception โ€‹

  • HTTPException โ†’ Throw structured errors.

๐Ÿ” Proxy โ€‹

  • proxy โ†’ Forward requests to another origin.

๐ŸŒ Runtime-specific Connection Info โ€‹

  • getConnInfo(type) โ†’ Dynamically load connection info for bun, deno, cloudflare, vercel.