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 โ
cachecompressโ 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_methodto override HTTP methods.
๐ง Combine โ
some,every,exceptโ Combine route conditions or logic.
๐งพ Accepts โ
acceptsโ Handle content negotiation.
๐งผ Powered By โ
poweredByโ AddX-Powered-Byheader.
๐งผ 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.
