I'm running into CORS issues using the Wiremock standalone jar. I call my mock service using jQuery ajax. Is it possible to add the required "Access-Control-Allow-Origin" header when starting up the server?
Asked
Active
Viewed 4,015 times
2 Answers
4
I got it to work by adding an options.json file in my mappings folder for the CORS preflight request
{
"request" : {
"url" : "/myurl",
"method" : "OPTIONS"
},
"response" : {
"status" : 200,
"headers" : {
"Access-Control-Allow-Origin" : "http://myorigin",
"Access-Control-Allow-Headers": "accept, content-type",
"Access-Control-Allow-Methods": "GET, POST"
}
}
}
and all my other mappings look like this
{
"request" : {
"urlPattern" : "/myurl",
"method" : "POST",
"bodyPatterns" : [ {
"equalToJson" : "{\"foo\":0}",
"jsonCompareMode" : "LENIENT"
} ]
},
"response" : {
"status" : 200,
"bodyFileName" : "body-file.json",
"headers" : {
"Access-Control-Allow-Origin" : "*"
}
}
}
hope it helps
-
@user372132- Can you give little more detail explanation about url,Access-Control-Allow-Origin? – ketan May 03 '17 at 09:16
1
I managed to make it work, with wiremock in standalone just adding enable-stub-cors
flag.
java -jar wiremock-standalone-2.27.2.jar --enable-stub-cors

whoami - fakeFaceTrueSoul
- 17,086
- 6
- 32
- 46