-
Notifications
You must be signed in to change notification settings - Fork 3
Support method OPTIONS for routes #140
Comments
Hi @kariem, The server automatically handle the OPTIONS method because it is usually used for front-end development, and these requests are automatically done by the browsers, so I thought it would be useful to not have to add those routes manually always. But you're right, in some scenarios it may be desirable to disable this behaviour and handle them manually. Another problem is that there is no mention in the documentation about it, so I will try to publish a new version as soon as possible including an option to disable the built-in CORS middleware, and mention it in the docs. For the moment, as a workaround, if you are modifying the code by yourself, you could also disable the CORS middleware removing the line Thanks for your feedback! 🙂 |
Hi again @kariem! The version 2.1.0 is already released, and the docs were also updated. Now it supports OPTIONS, HEAD and TRACE methods, and it has two new options allowing to disable both CORS headers and CORS pre-flight responses separately. You can read the "how to use the OPTIONS method" section in the documentation for further info. I hope it might help, |
Hi @javierbrea, Thank you very much for the quick update! Just tested 2.1.0 with the adapted configuration and it works well. Thank you! |
The API I would like to mock, uses
OPTIONS
requests. When I try to use this in a route, I get an errorThe error I see in the sever log
However, when I set the method to
GET
orPOST
everything seems to work fine.I have also noticed that the server tries to respond to CORS preflight requests and this seems to be the reason for this problem. When I try to extend the constant
METHODS
inMock.js
with a line forOPTIONS
, there is no error, but the response from the server containsAlthough, I never included these headers in the request
If there is no easy way to implement this, is there a possible workaround?
The text was updated successfully, but these errors were encountered: