--- URL: "/guide/core/utils" LLMS_URL: "/guide/core/utils/llms.txt" --- # `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`.