Fork me on GitHub
#beginners
<
2024-03-10
>
dixie14:03:11

hello, I'm building compojure api service and it is behind reverse http proxy (with url rewrite rule /external-name/ -> /). It works fine except swagger ui (it expects everything on / instead of /external-name/). Is there a way to tell comporuje/compojure-api/swagger or ring/jetty that it is behind reserve http proxy and base path is /external-name/ instead of "/")? Or am I expecting some non-existing magic instead of simply creating my routing rules with /external-name/? 🙂

phill15:03:56

Everything is fine except Swagger generates incorrect HTML hyperlinks?

dixie16:03:01

Answer to your question: Yes. Hyperlinks are wrong. well, I wasn't probably very clear. I'm using lighttpd with url-rewrite rule, so http://external.example.com/external-name/api/service is forward to http://localhost:3000/api/service (and the /external-name/ is stripped from URL in forward request). remark: My "service" is very simple, the response is some string without any URL/URI so it isn't relevant if external URL (/external-name/api/service) is different to internal (/api/service). but that isn't case for swagger which generates URL and it assumes is /api/service. As a workaround I set routing rules in comporuje-api including external-name and removed lighttpd url-write rule. Now everything works (there is no any difference between external and internal URL, except hostname), but I'm not sure if this is state-of-art approach for comporuje-api behind reserve http proxy.

phill16:03:22

In general, it's most flexible to produce relative hyperlinks. Swagger probably has a setting for the context root. But in any case, Compojure just generates a Ring handler, so you could wrap it with another Ring handler that "restored" /external-name to the request map before relaying the request to Compojure.

👍 2