-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Does fastify contain cors ? #326
Comments
Good question. We should definitely support this as a plugin. @delvedor WDYT. |
We could take this as a roadmap. |
It is not supported in core, but it could be a perfect plugin! |
you can use the http://npm.im/cors module through our middleware support. |
Example const cors = require('cors')
fastify.use(cors()) @mcollina but we don't provide a way to attach specific middlewares to a route correct? |
@StarpTech it should be |
This looks like it does the trick: https://github.com/fastify/middie#restrict-middleware-execution-to-a-certain-paths |
closing as it should be solved. |
won't CORS be implemented as a plugin? current cors solution fails to handle so-called preflight request cors problem. see
In preflight request situation, the client will first send an I am not sure about the detail, but using express didn't expose such a problem. |
I think we should do a plugin for cors. If you look at: https://github.com/expressjs/cors#enabling-cors-pre-flight, you can see how they define the options route for a request. IMHO our plugin should define Side note, the following might just work together with the fastify.route({
method: 'OPTIONS'
path: '*'
}, (request, reply) => { reply.send() }) @zhaoyao91 let me know if that works for you. |
Thanks for your advices, we made it successfully. @mcollina @zhaoyao91 In our practice, when we send a preflighted request by XMLHttpRequest in client, it will first send an options request, so we make it successfully by using cors and fastify.options in our plugins .
|
I'm working on a plugin :) |
Closed in #1076 :) |
As titled. Related: #326 #### Checklist - [ ] run `npm run test` and `npm run benchmark` - [ ] tests and/or benchmarks are included - [x] documentation is changed or added - [x] commit message and code follows [Code of conduct](https://github.com/fastify/fastify/blob/master/CODE_OF_CONDUCT.md)
But you have write it in every file if you are using prefix |
Does fastify contain cors
thx
The text was updated successfully, but these errors were encountered: