Iwan
12/27/2024, 1:36 AMservices:
wiremock:
image: "wiremock/wiremock:latest"
container_name: arc_e_tect_sedr_iff_wiremock
ports:
- "9091:8080"
volumes:
- type: bind
source: ./wiremock/__files/
target: /home/wiremock/__files/
- type: bind
source: ./wiremock/mappings/
target: /home/wiremock/mappings/
environment:
- WIREMOCK_OPTIONS="--proxy-all"
entrypoint: ["/docker-entrypoint.sh", "--global-response-templating", "--verbose"]
I have two endpoints, one is stubbed by WireMock at <http://localhost:9091/syshealth>
and that works perfect. The other is supposed to be proxied, which is at <http://localhost:9091/>
and should be proxied to <http://localhost:9090>
.
From the documentation I could find that the above Docker compose file should work, when I use the following file and place it in `mappings`for the endpoint that I want proxied:
{
"request": {
"method": "GET",
"url": "/"
},
"response": {
"proxyBaseUrl": "<http://host.docker.internal:9090/>"
}
}
But it turns out that it doesn't work. When I open the proxied URL <http://localhost:9090>
, I do get the response:
{
"mockedBy": "WIREMOCK"
}
But when I go to <http://localhost:9091>
, the call is not routed to <http://localhost:9090>
and I get an error stating:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Dec 27 02:44:31 CET 2024
There was an unexpected error (type=Not Found, status=404).
In the logs of WireMock I see the following lines:
2024-12-27 03:00:03 2024-12-27 02:00:03.721 Request received:
2024-12-27 03:00:03 172.20.0.1 - GET /
2024-12-27 03:00:03
2024-12-27 03:00:03 Host: [localhost:9091]
2024-12-27 03:00:03 Connection: [keep-alive]
2024-12-27 03:00:03 Cache-Control: [max-age=0]
2024-12-27 03:00:03 sec-ch-ua: ["Microsoft Edge";v="131", "Chromium";v="131", "Not_A Brand";v="24"]
2024-12-27 03:00:03 sec-ch-ua-mobile: [?0]
2024-12-27 03:00:03 sec-ch-ua-platform: ["Windows"]
2024-12-27 03:00:03 DNT: [1]
2024-12-27 03:00:03 Upgrade-Insecure-Requests: [1]
2024-12-27 03:00:03 User-Agent: [Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0]
2024-12-27 03:00:03 Accept: [text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7]
2024-12-27 03:00:03 Sec-Fetch-Site: [none]
2024-12-27 03:00:03 Sec-Fetch-Mode: [navigate]
2024-12-27 03:00:03 Sec-Fetch-User: [?1]
2024-12-27 03:00:03 Sec-Fetch-Dest: [document]
2024-12-27 03:00:03 Accept-Encoding: [gzip, deflate, br, zstd]
2024-12-27 03:00:03 Accept-Language: [en-GB,en;q=0.9,en-US;q=0.8,nl;q=0.7,de-DE;q=0.6,de;q=0.5]
2024-12-27 03:00:03 Cookie: [Idea-524f0736=833873b3-2dba-4c0b-b23a-32dd0740e280; Idea-524f0737=18638ed5-d786-489c-b36b-ce4fd759e37a; Idea-524f0738=85b5714c-037c-4f80-927e-f4535226bdf2]
2024-12-27 03:00:03 sec-gpc: [1]
2024-12-27 03:00:03
2024-12-27 03:00:03
2024-12-27 03:00:03
2024-12-27 03:00:03 Matched response definition:
2024-12-27 03:00:03 {
2024-12-27 03:00:03 "status" : 200,
2024-12-27 03:00:03 "proxyBaseUrl" : "<http://host.docker.internal:9090/>"
2024-12-27 03:00:03 }
2024-12-27 03:00:03
2024-12-27 03:00:03 Response:
2024-12-27 03:00:03 HTTP/1.1 404
2024-12-27 03:00:03 Keep-Alive: [timeout=60]
2024-12-27 03:00:03 Vary: [Origin, Access-Control-Request-Method, Access-Control-Request-Headers]
2024-12-27 03:00:03 Content-Length: [275]
2024-12-27 03:00:03 Date: [Fri, 27 Dec 2024 02:00:04 GMT]
2024-12-27 03:00:03 Content-Language: [en-GB]
2024-12-27 03:00:03 Content-Type: [text/html;charset=UTF-8]
2024-12-27 03:00:03
I've been trying to get this to work, as it would allow me to gradually replace proxied endpoints by real implementations.
Help would be highly appreciated.Lee Turner
12/27/2024, 11:53 AM--proxy-all
option you have. Could you remove that and try without it? If you look here, you can see the --proxy-all
option needs a url passed along with the command line option.
I don't think you need the --proxy-all
option with configuring your proxy via a stub - https://wiremock.org/docs/proxying/Iwan
12/27/2024, 6:08 PM--pass-all
option, like: --proxy-all=<http://host.docker.internal:9090>
, seems to work but only because it will proxy all requests unless it finds a matching stub. So it will work when I delete the stub:
{
"request": {
"method": "GET",
"url": "/"
},
"response": {
"proxyBaseUrl": "<http://host.docker.internal:9090/>"
}
}
Apparently, this method doesn't work when WireMock is running in a Docker container. Although I must admit that I haven't tested it with WireMock running in a different stand-alone setup.Lee Turner
12/27/2024, 6:31 PMIwan
12/27/2024, 7:43 PMIwan
12/29/2024, 8:37 PM{
"request": {
"method": "GET",
"url": "/"
},
"response": {
"proxyBaseUrl": "<http://host.docker.internal:9090/>"
}
}
but instead I should have specified:
{
"request": {
"method": "GET",
"url": "/"
},
"response": {
"proxyBaseUrl": "<http://host.docker.internal:9090>"
}
}
Hope you notice the difference, but it is the /
at the end of: "proxyBaseUrl": "<http://host.docker.internal:9090>"
. Turns out that it shouldn't be there. Without the /
all works as advertised.Lee Turner
12/29/2024, 8:38 PM