Skip to content

Commit 7b1ee06

Browse files
authored
docs: update asynchronous example (#205)
1 parent d0ec096 commit 7b1ee06

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,19 @@ You can use it as is without passing any option or you can configure it as expla
6767
```js
6868
const fastify = require('fastify')()
6969

70-
fastify.register(require('@fastify/cors'), function (instance) {
71-
70+
fastify.register(require('@fastify/cors'), (instance) => {
7271
return (req, callback) => {
73-
let corsOptions;
74-
const origin = req.headers.origin
72+
const corsOptions = {
73+
origin: true
74+
};
75+
7576
// do not include CORS headers for requests from localhost
76-
const hostname = new URL(origin).hostname
77-
if(hostname === "localhost"){
78-
corsOptions = { origin: false }
79-
} else {
80-
corsOptions = { origin: true }
77+
if (/localhost/.test(req.headers.origin)) {
78+
corsOptions.origin = false
8179
}
82-
callback(null, corsOptions) // callback expects two parameters: error and options
80+
81+
// callback expects two parameters: error and options
82+
callback(null, corsOptions)
8383
}
8484
})
8585

0 commit comments

Comments
 (0)