Running wiremock standalone with a sub-path

566 views
Skip to first unread message

Aleksander Sumowski

unread,
May 27, 2022, 6:21:21 AM5/27/22
to wiremock-user
Hi all,
is there a way to run wiremock standalone with a subpath? I'd like to access admin interface using a path: /my-base-path-prefix/swagger-ui/#/ Or do I need to run eg nginx in front of the wiremock and rewrite the path?

Thanks,
Aleksander

Tom Akehurst

unread,
May 27, 2022, 6:40:57 AM5/27/22
to wiremock-user
You could write a request filter and load it as an extension, using it to remap one URL form to the other.

Here's an example implementation of an admin request filter: https://github.com/wiremock/wiremock/blob/master/src/test/java/com/github/tomakehurst/wiremock/RequestFilterAcceptanceTest.java#L236

General info about creating and registering extensions here: https://wiremock.org/docs/extending-wiremock/


Aleksander Sumowski

unread,
May 31, 2022, 9:05:53 AM5/31/22
to wiremock-user
So I've tried the nginx approach first as I was more familiar with this approach: rewriting the request before it was reaching Wiremock to remove the /my-base-path-prefix/

That caused issues with Swagger though. When the request eg
reaches Swagger it doesn't contain /my-base-path-prefix/ so the callback makes a request back to the server ignoring it which causes the callback request to be routed incorrectly...

Would going with the filter approach help to deal with this issue as well?

Thanks,
Aleksander

--
You received this message because you are subscribed to a topic in the Google Groups "wiremock-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wiremock-user/6QwAOnjPnQk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wiremock-use...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/wiremock-user/72b673b6-a7f4-4e54-be23-a6865166519fn%40googlegroups.com.

Tom Akehurst

unread,
May 31, 2022, 9:56:15 AM5/31/22
to wiremock-user
Hmmm...not sure there's an easy fix for that one, other than perhaps hacking the OpenAPI spec to include base path attribute that matches your base path.

Aleksander Sumowski

unread,
Jun 1, 2022, 4:16:24 AM6/1/22
to wiremock-user
hmmm, and would running wiremock in a servlet container deployed under a sub-path of the context root solve those issues? Feels like a heavy-weight solution but maybe the best one?

Thanks for all the answers!

Tom Akehurst

unread,
Jun 1, 2022, 5:19:54 AM6/1/22
to wiremock-user
That wouldn't help, as the servlet container would effectively be doing the same thing i.e. rewriting URL paths on the way in.

Can you elaborate why you need to run on a different path in this way, given that you're not already running in a shared servlet container?

Aleksander Sumowski

unread,
Jun 1, 2022, 6:14:05 AM6/1/22
to Tom Akehurst, wiremock-user
Wiremock is running in a sidecar container in a k8s pod - this is a requirement of a base helm chart maintained by the infra team. We're running WireMock in dev environment to provide stubbed responses for other teams to develop against our services. Ingress needs a path to route traffic to the right port to reach the right container. The base path is used by the actual service, so I need to use additional path prefix

Thanks,
Aleksander

Tom Akehurst

unread,
Jun 1, 2022, 6:27:35 AM6/1/22
to wiremock-user
In this situation I'd normally try to run WireMock on a different port number and have the service select on that. Is that not an option here?

Or run WireMock in its own deployment rather than as a sidecar to another?

Reply all
Reply to author
Forward
0 new messages