Cloudflare - v1.3.0
    Preparing search index...

    Module middlewares

    The Hono delivery layer — the middleware a Worker registers on its app.

    A separate subpath, imported as @bayudwiyansatria/cloudflare/http:

    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 SecurityMiddleware short-circuits a rejected request, so logToAnalytics goes first if a 401 is to leave a log line and a metric behind. The other way round it leaves nothing.

    const app = new Hono()

    app.use('*', logToAnalytics) // first, so rejections are still observed
    new SecurityMiddleware().apply(app)

    Bayu Dwiyan Satria

    1.0.0

    1.0.0

    SecurityMiddleware
    logToAnalytics