Skip to content

Commit

Permalink
fix example (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eomm committed Oct 4, 2021
1 parent e722027 commit f06a9bb
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,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'), (instance) => (req, callback) => {
let corsOptions;
// do not include CORS headers for requests from localhost
if (/localhost/.test(origin)) {
corsOptions = { origin: false }
} else {
corsOptions = { origin: true }
fastify.register(require('fastify-cors'), function (instance) {
return (req, callback) => {
let corsOptions;
const origin = req.headers.origin
// do not include CORS headers for requests from localhost
if (/localhost/.test(origin)) {
corsOptions = { origin: false }
} else {
corsOptions = { origin: true }
}
callback(null, corsOptions) // callback expects two parameters: error and options
}
callback(null, corsOptions) // callback expects two parameters: error and options
})
fastify.get('/', (req, reply) => {
Expand Down

0 comments on commit f06a9bb

Please sign in to comment.