-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
asynchronous dynamic cors not even worked! #137
Labels
Comments
Indeed documentation is off. fastify.register(require('fastify-cors'), (instance) => (req, callback) => {
let corsOptions;
// do not include CORS headers for requests from localhost
if (/localhost/.test(req.getHeader(origin))) {
corsOptions = { origin: false }
} else {
corsOptions = { origin: true }
}
callback(null, corsOptions) // callback expects two parameters: error and options
})
fastify.get('/', (req, reply) => {
reply.send({ hello: 'world' })
}) Which is still confusing. See this test for more explicit use case: fastify-cors/test/cors.test.js Lines 184 to 276 in 05419b0
|
Ok found a solution :
This can dynamically match all kind of origin and assign cors for each route. its working so far. |
I was sorry when I saw it 😟 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisites
Fastify version
latest
Plugin version
latest
Node.js version
14
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
win10
Description
yo your origin is pointing to nothing. How to fix this? I know it suppose to be an object?
Steps to Reproduce
.test(origin) points to undefined man
Expected Behavior
origin should not be undefined
The text was updated successfully, but these errors were encountered: