@tinyhttp/unless

Unless middleware for tinyhttp that executes a middleware conditionally.

Install

pnpm i @tinyhttp/unless

API

unless(middleware, (UnlessMiddlewareOptions | CustomUnless))

The UnlessMiddlewareOptions object can include:

The CustomUnless is a function that receives a Request object and returns a boolean. The result of the function will determine if the execution of the middleware is skipped.

Example

import { App } from '@tinyhttp/app'
import { unless } from '@tinyhttp/unless'
import { cors } from '@tinyhttp/cors'

const app = new App()

app.use(unless(cors(),  { method: ['GET', 'POST'] }))


app.use(unless(cors(), { ext: '/public' }))


app.use(unless(cors(), (req) => req.method === 'GET')

app.use(unless(cors(), { path: ['/content/public', /user/, { url: '/public', methods: ['GET'] }] })

app.listen(3000)

Install

pnpm i @tinyhttp/unless

Version

1.0.18

Source

packages/unless