Layer7 API Management

  • 1.  Maintain custom path at browser / client?

    Posted Feb 09, 2018 04:53 PM

    I'm trying to create a reverse proxy with a custom path that the application itself doesn't use. But having problems trying to maintain the path when all the href within the application may be like /something/other . This would be dynamic and change based on app.

     

    What the applications wanted was having a common entry hostname but custom paths to apps.

     

    =======

    Example:

    my.domain/app1/   -- reverse proxy --> myapp1.domain/engineering

    my.domain/app2/ -- reverse proxy --> myapp2.domain/

    my.domain/app3/ -- reverse proxy --> myapp3.domain/something/other

     

    They want the /appX/ to be maintained through redirects, href links, etc. 

     

    I've got the /app1/ being removed on the route, that's simple enough. What I'm not quite sure about is how to ensure that the /app1/ is maintained through all redirects (location rewrite should handle the 302s etc I assume) but like JS sending me to another spot breaks out. 

     

    =======

    Problem Example

     

    - User goes to my.domain/app1/ and traffic proxied to myapp1.domain/engineering

    - myapp1.domain/engineering slaps "/engineering/default/home" and user ends up at to my.domain/engineering/default/home and gets error.

     

    I need all of that to be my.domain/app1/engineering/default/home

    =======

     

    Is this doable? Or good documentation somewhere I can follow? I've tried finding it in the docops but not seeing this specific case since their publish proxy is hostname routing examples. 



  • 2.  Re: Maintain custom path at browser / client?

    Broadcom Employee
    Posted Feb 12, 2018 05:03 PM

    Dear CBertagnolli ,

    To successfully reverse proxy, we need to translate the uri correctly.

    The default reverse proxy template uses regular expression to translate the uri (in the body, cookie, header, etc.)-- for request, replace ${requestHost} to ${webAppHost}; for response, replace ${webAppHost} back to ${requestHost}

     

    In your case, the ${requestHost} = my.domain/app1/  ; ${webAppHost} = myapp1.domain/engineering

     

    So, only the uri in the response matching the pattern 'myapp1.domain/engineering' will be translated.

    It looks like your backend server changes 'myapp1.domain/engineering' to '/engineering', it cannot be translated as it's unknown in your reverse policy.

     

    For your response, if you need to map both 'myapp1.domain/engineering' and '/engineering' to 'my.domain/app1', one default regex is not enough, you may add one more regex against response to replace '/engineering' to 'my.domain/app1'

     

    Regards,

    Mark



  • 3.  Re: Maintain custom path at browser / client?

    Broadcom Employee
    Posted Feb 12, 2018 05:11 PM

    It very depends on how your backend implemented, if for the next  transaction, it requires '/engineering/default/home' rather than 'myapp1.domain/engineering/default/home' (after translation), you may also need to check the regex against  request, too.



  • 4.  Re: Maintain custom path at browser / client?

    Broadcom Employee
    Posted Feb 12, 2018 05:32 PM

    It can be quite tricky, depending on the backend application.  Most cases are fairly simple since a specific backend generates it's URL's fairly consistently - so a few simple rules can be applied.   In the odd case you end up with somethng tricky, such as the root of the document set in a javascript variable and all links generated via javascript function.

     

    Usually it is possible to write a few regex to do the proxyreverse parsing of any hardcoded url's in the document.  But sometimes it can be difficult - particularly if the backed is hand crafted, you need to consider things like case sensitivity HTTP://WWW.SErVER.COM  , and white space ref"=http:  //www.server.com"  and links generated in javascript.

     

    Cheers - Mark



  • 5.  Re: Maintain custom path at browser / client?
    Best Answer

    Posted Feb 13, 2018 01:05 PM

    The first one we are looking at has lots of links without hostnames etc and JS handling a bunch from what I can tell. 

     

    Was hoping there was some magic missile I could just cast at this to solve it...but seems like we'll have to dig through it - COTS app - and see how it all works. From what I can tell all the href are just like /assets/images/blah; which that should be simple enough to look for href and add /app/ to them, or the src ones too.

     

    But there's also some JS on some pages it looks like handling images and other redirects. I've gotta little knowledge of that level of stuff so get a little lost digging under there ...

     

    E.g.,

    window.getContextPath() + '/resources/image/someimage.gif';

     

    Maybe not worth the effort and just have them use a unique hostname O_o.