All files / src/middlewares index.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 2/2
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                                                                    16x 28x  
/**
 * The Hono delivery layer — the middleware a Worker registers on its app.
 *
 * @remarks
 * A separate subpath, imported as `@bayudwiyansatria/cloudflare/http`:
 *
 * ```ts
 * import { logToAnalytics, SecurityMiddleware } from '@bayudwiyansatria/cloudflare/http'
 * ```
 *
 * Separate so `hono` can stay an optional peer dependency. Nothing on the main
 * entry knows how a request arrived, so a Worker on another framework — or none
 * — can use the bindings without installing Hono. Folding these two files into
 * the main barrel would resolve the import eagerly and make the peer mandatory
 * for everyone. An ESLint rule keeps Hono confined to this directory.
 *
 * Registration order matters where these two meet. Hono runs middleware in
 * registration order and {@link SecurityMiddleware} short-circuits a rejected
 * request, so {@link logToAnalytics} goes first if a `401` is to leave a log
 * line and a metric behind. The other way round it leaves nothing.
 *
 * @example
 * ```ts
 * const app = new Hono()
 *
 * app.use('*', logToAnalytics)     // first, so rejections are still observed
 * new SecurityMiddleware().apply(app)
 * ```
 *
 * @module
 * @author Bayu Dwiyan Satria
 * @version 1.0.0
 * @since 1.0.0
 */
export { SecurityMiddleware } from '@/middlewares/SecurityMiddleware'
export { logToAnalytics } from '@/middlewares/logger'