node-restify: OPTIONS does not work with CORS by default
I received the error message:
405 (Method Not Allowed)
when making an OPTIONS request. Backbone does this by default.
There seems to be lots of discussion about it in issue #284, but I didn’t find a solution that worked with node-restify 2.8.2.
The code I am using is:
server.pre(restify.CORS());
server.use(restify.fullResponse());
What is the current recommended solution?
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 2
- Comments: 20 (6 by maintainers)
Commits related to this issue
- fix(CORS): Enable CORS Reference:https://github.com/restify/node-restify/issues/664 — committed to TonyChol/tinyurl-api by TonyChol 8 years ago
Thanks @Qwerios This is my configuration in order to make angular-jwt work with restify.
I hope it may be helpful for someone.
I’ll add here the code I’m now adding to each of my API projects to get CORS to work. Feel free to use or abuse it at your leisure…
I’m facing this problem with Angular’s $http, and restify v2.8.4.
I am also using:
and this solves the problem:
Is this the recommended solution? Is there a reason this isn’t enabled by default?
Michael, feel free to submit a PR Iinstead of raging about an open source framework maintained by folks for free.
On Tuesday, October 6, 2015, Michel Boudreau notifications@github.com wrote:
Via mobile
The problem seems to be that Backbone sends a couple extra headers that broke the CORs preflight.
I solved the problem by using:
Shame CORs is not more developer friendly. I had to fully understand CORs before I could solve it.
Express didn’t have this problem. Perhaps they add more headers by default? Perhaps that is worth considering for other restify developers?
The CORS module has found a new home and has been updated to be both correct and stable 😄
https://github.com/TabDigital/restify-cors-middleware/
I believe the recent changes address this issue, if I’m missing a nuance here please comment and I’d be happy to re-open this issue to discuss. We could also migrate this issue over to the new repo if needed ❤️
Better solution than having an event on top of
MethodNotAllowed
(Just if you don’t need to deploy any route on OPTIONS method).