skip to Main Content

I have installed a Traefik v2.x reverse-proxy. It receives the request from external apps and pass them to a SOAP API back-end.
The SOAP service respond with a WSDL file. In this WSDL (XML) file (in the HTTP response body), I have a string (an URL) that is incorrect and I want to rewrite it before Traefik sending the response back to the calling app.

I know that it exists a module to do that using nginx (http_sub_module) but is it possible to do it with Traefik? I haven’t found a middleware fitting my needs.

Thank you for your time and your answers.

2

Answers


  1. Chosen as BEST ANSWER

    In the latest versions of Traefik (2.9.x for example), there is now no need to registrer to Traefik Pilot program to get access to the plugin repository.

    Thus, you can add plugin freely following the Traefik plugin installation guide.

    The plugin fitting my needs is the rewriteBody plugin.

    To use it, you have to update your static configuration adding this:

    experimental:
      plugins:
        rewritebody:
          moduleName: "github.com/traefik/plugin-rewritebody"
          version: "v0.3.1"
    

    And you can use it in your dynamic configuration like

    http:
      routers:
        test-router:
          entryPoints:
            - "websecure"
          rule: "Host(`your.domain.org`) && PathPrefix(`/path`)"
          middlewares:
            - test-rewritebody
          service: test
          tls: {}
    
       middlewares:
         test-rewritebody:
           plugin:
             rewritebody:
               lastModified: "true"
               rewrites:
                 - regex: foo
                   replacement: bar
    

    And this works perfectly!


  2. I ended up using nginx (http_sub_module, subsitutions) behind Traefik, that way you can use both nginx and Traefik features!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search