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
โ AddX-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 forbun
,deno
,cloudflare
,vercel
.