How to setup standalone wiremock server under an application path

Viewed 284

I am trying to setup wiremock under an application path.

I have wiremock dockerized and running under some path https://local.wiremock/ and that works fine, so I can access the admin like this https://local.wiremock/__admin/docs

However when I deploy to aws it needs to be under a path like this: https://aws-server.wiremock/simulator/__admin/docs

And the addition of the application path /simulator breaks everything.

So I want to set it up locally so that it runs under: https://local.wiremock/simulator/__admin/docs

I have been going through documentation and there's nothing there for standalone server configuration. There is a mappedUnder xml field that could be useful but it cannot be set via docker.

Any ideas how to achieve that?

1 Answers

I think you could do this by adding a Request Wrapper. The idea behind the Request Wrapper is that it intercepts the request and allows you to modify it before sending the request on. I think your solution would look something like...

public static class removeSimulatorPath extends StubRequestFilter {

    @Override
    public RequestFilterAction filter(Request request) {
        Request wrappedRequest = RequestWrapper.create()
                // lambda to replace the current URL with one without `/simulator`
                .transformAbsoluteUrl(url -> url.replace("/simulator", "")
                .wrap(request);

        return RequestFilterAction.continueWith(wrappedRequest);
    }

    @Override
    public String getName() {
        return "remove-simulator-path";
    }
}
Related