File tree Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -67,19 +67,19 @@ You can use it as is without passing any option or you can configure it as expla
67
67
``` js
68
68
const fastify = require (' fastify' )()
69
69
70
- fastify .register (require (' @fastify/cors' ), function (instance ) {
71
-
70
+ fastify .register (require (' @fastify/cors' ), (instance ) => {
72
71
return (req , callback ) => {
73
- let corsOptions;
74
- const origin = req .headers .origin
72
+ const corsOptions = {
73
+ origin: true
74
+ };
75
+
75
76
// 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
81
79
}
82
- callback (null , corsOptions) // callback expects two parameters: error and options
80
+
81
+ // callback expects two parameters: error and options
82
+ callback (null , corsOptions)
83
83
}
84
84
})
85
85
You can’t perform that action at this time.
0 commit comments