Skip to content

Commit

Permalink
Merge pull request #9 from michealroberts/docs/README/onRequestCORSMi…
Browse files Browse the repository at this point in the history
…ddleware

docs: Updated README.md with onRequestCORSMiddleware() middleware utility usage.
  • Loading branch information
michealroberts authored Aug 30, 2023
2 parents a2c1445 + 7cb2a32 commit 6a66d90
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ nitro native CORS event handler.

## Requirements

- [nitro](https://nitro.unjs.io) v.2.4.\* or higher
- [nitro](https://nitro.unjs.io) v.2.6.\* or higher

## Installation

Expand All @@ -22,9 +22,22 @@ yarn add nitro-cors

## Usage

nitro CORS is built upon the h3 cors library. To read more about h3's inbuilt cors library, please consult the [h3 repository](https://github.com/unjs/h3#utilities).
nitro CORS is built upon the h3 CORS utilities provided by the h3 library. To read more about h3's inbuilt cors library, please consult the [h3 repository](https://github.com/unjs/h3#utilities).

nitro-cors aims to provide a simple wrapper to define a CORS event handler per nitro event handler, or per route. To use it, simply import the `defineCORSEventHandler` function and wrap your event handler with it as follows:
To get started, you can enable CORS on a specific event handler by using the object syntax definitions intorduced in nitro v2.6.0 and h3 v1.8.0 as follows:

```ts
import { cors } from 'nitro-cors'

export default eventHandler({
onRequest: [cors],
async handler(event) {
return 'Hello CORS!'
}
})
```

nitro-cors also provides a simple wrapper to define a CORS event handler per nitro event handler, or per route. To use it, simply import the `defineCORSEventHandler` function and wrap your event handler with it as follows:

```ts
import { defineCORSEventHandler } from 'nitro-cors'
Expand Down

0 comments on commit 6a66d90

Please sign in to comment.