Skip to content

Commit

Permalink
docs: update asynchronous example (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
is2ei authored May 29, 2022
1 parent d0ec096 commit 7b1ee06
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ You can use it as is without passing any option or you can configure it as expla
```js
const fastify = require('fastify')()
fastify.register(require('@fastify/cors'), function (instance) {
fastify.register(require('@fastify/cors'), (instance) => {
return (req, callback) => {
let corsOptions;
const origin = req.headers.origin
const corsOptions = {
origin: true
};
// do not include CORS headers for requests from localhost
const hostname = new URL(origin).hostname
if(hostname === "localhost"){
corsOptions = { origin: false }
} else {
corsOptions = { origin: true }
if (/localhost/.test(req.headers.origin)) {
corsOptions.origin = false
}
callback(null, corsOptions) // callback expects two parameters: error and options
// callback expects two parameters: error and options
callback(null, corsOptions)
}
})
Expand Down

0 comments on commit 7b1ee06

Please sign in to comment.