Open tparikka opened 3 years ago
I made a change to my imposter, adding "Access-Control-Allow-Origin": "http://app.local.com"
to the headers of my response and that got things going. I'm new-ish to CORS, so I'm wondering is it just understood that I have to explicitly add that header to each of my responses where I expect to be making a request cross-origin? I had thought that adding the origin in the startup of Mountebank would handle that part for me.
This also appears to impact proxy
response types, because the proxy doesn't return the Access-Control-Allow-Origin
header. Unlike the is
response type, I don't think I can actually work around this because the proxy doesn't allow for injection of headers.
I worked on a little project that could be helpful: https://github.com/sidilabs/mock-server
This project creates a gulp task to communicate with Mountebank and generate a series of imposters following a defined structure, even if you don't plan to use the project as it is, you could use some of the code to solve a specific problem.
I'm attempting to use Mountebank in between a front-end website and an ASP.NET Core API to facilitate automated UI testing. Reading the release notes for v2.3.3 I see that the --origin CLI flag is required to accept requests from a different origin. I ran mb with the origin flag and created my imposter with the allowCORS option set true, but still get a CORS error. Thank you in advance for any help you can offer!
Expected behaviour
When starting mountebank with
npx mb --origin "http://app.local.com"
, I would expect that requests made to Mountebank from a different origin with a header of"Origin":"http://app.local.com"
should succeed.Actual behaviour
When I try to request data from Mountebank from a different origin I get the error
Access to XMLHttpRequest at 'http://app.local.com:8080/api/case/search/' from origin 'http://app.local.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
.Steps to reproduce
npx mb --origin "http://app.local.com"
Software versions used
Log contents in mb.log when running mb --loglevel debug