@tinyhttp/cors

npm (scoped) npm

A rewrite of expressjs/cors module.

HTTP cors header middleware

Install

pnpm i @tinyhttp/cors

API

import { cors } from '@tinyhttp/cors'

cors(options)

Returns the CORS middleware with the settings specified in the parameters

Options

The default configuration is:

{
  "origin": "*",
  "methods": ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"],
  "optionsSuccessStatus": 204
}

Example

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

const app = new App()

app.use(cors({ origin: 'https://myfantastic.site/' }))
app.options('*', cors())

app.get('/', (req, res) => {
  res.send('The headers contained in my response are defined in the cors middleware')
})

app.listen(3000)

Alternatives

License

MIT © BRA1L0R

Install

pnpm i @tinyhttp/cors

Version

0.2.20

Source

packages/cors