Can a reverse-proxy be setup such that internal routes do not need to adjust to the outer servers URLs?

63 views
Skip to first unread message

larry google groups

unread,
Jul 14, 2014, 12:25:28 AM7/14/14
to comp...@googlegroups.com
I searched this group for:

reverse proxy route/resources

but I found not discussions on this topic, which I find surprising.

I was developing an app and testing it on my local machine. I established my routes like this:


(defroutes app-routes
  (GET "/" request (login-form request))
  (POST "/" request (login request))
  (OPTIONS "/" request (preflight request))
  (GET "/signup" request (signup-form request))
  (PUT "/signup" request (signup request))
  (OPTIONS "/signup" request (preflight request))
  (GET "/examples" [] (examples))
  (route/resources "/")
  (route/not-found "Page not found. Please go to /examples to see how you should use this software."))

(def app
  (-> app-routes
      (wrap-cookies)
      (wrap-keyword-params)
      (wrap-multipart-params)
      (wrap-nested-params)
      (wrap-params)
      (wrap-json-params)
      (wrap-content-type)
      (wrap-not-modified)))

I had a folder layout such that:

/resources
    /templates
    /public
        /img
        /js
        /css

The templates had links in them such as: 

    <link rel="stylesheet" href="/css/bootstrap.css" />
    <link rel="stylesheet" href="/css/admin.css" />

Everything worked. I then moved this to the real server where this software will live. That server is running Apache. I established a reverse proxy like this:

        ProxyPreserveHost on
        ProxyPass /api http://127.0.0.1:34000/
        ProxyPassReverse /api http://127.0.0.1:34000/

        ProxyPass /login http://127.0.0.1:34001/
        ProxyPassReverse /login http://127.0.0.1:34001/

and then none of my links to CSS or JS worked. I had to change the URLs like this:

    <link rel="stylesheet" href="/login/css/bootstrap.css" />
    <link rel="stylesheet" href="/login/css/admin.css" />

Maybe that should have been obvious to me. But I wonder if there is a way to set up a reverse proxy such that I would not have to change the URLs in my templates? Is there a way to insulate my Clojure app from whatever URLs Apache is seeing? 








James Reeves

unread,
Jul 14, 2014, 7:32:00 AM7/14/14
to Compojure
A lot of reverse proxies don't alter the body of the response, as that's a strategy that's very prone to error.

I'd approach this problem by setting a configuration variable to hold the prefix, and then adding this to the URLs you generate. If you're using Hiccup, the wrap-base-url middleware can handle this for you.

- James


--
You received this message because you are subscribed to the Google Groups "Compojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to compojure+...@googlegroups.com.
To post to this group, send email to comp...@googlegroups.com.
Visit this group at http://groups.google.com/group/compojure.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages