Skip to content

Commit

Permalink
docs: update README to Fastify v4 (#216)
Browse files Browse the repository at this point in the history
* Update README to Fastify v4

Fixes #215

* Update README.md

* Update README.md

Co-authored-by: Uzlopak <aras.abbasi@googlemail.com>

Co-authored-by: Uzlopak <aras.abbasi@googlemail.com>
  • Loading branch information
mcollina and Uzlopak committed Jul 29, 2022
1 parent a9077db commit b4d7977
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ npm i @fastify/cors
## Usage
Require `@fastify/cors` and register it as any other plugin, it will add a `preHandler` hook and a [wildcard options route](https://github.com/fastify/fastify/issues/326#issuecomment-411360862).
```js
const fastify = require('fastify')()
import Fastify from 'fastify'
import cors from '@fastify/cors'

fastify.register(require('@fastify/cors'), {
const fastify = Fastify()
await fastify.register(cors, {
// put your options here
})

fastify.get('/', (req, reply) => {
reply.send({ hello: 'world' })
})

fastify.listen(3000)
await fastify.listen({ port: 3000 })
```
You can use it as is without passing any option or you can configure it as explained below.
### Options
Expand Down Expand Up @@ -86,8 +88,10 @@ fastify.register(require('@fastify/cors'), (instance) => {
}
})
fastify.get('/', (req, reply) => {
reply.send({ hello: 'world' })
fastify.register(async function (fastify) {
fastify.get('/', (req, reply) => {
reply.send({ hello: 'world' })
})
})
fastify.listen(3000)
Expand Down

0 comments on commit b4d7977

Please sign in to comment.