Hey guys, I am building a personal project, and I have splitted the front and backend into 2 different projects, so in fact, I have 2 different servers, one for the FE and another for the BE. Is there a way to use shadow-cljs to proxy the api requests to my backend server? Or is that the job for a nginx instance instead? Cheers
ok, thanks guys!
and to answer for the reason, yes, it is a requirement
Unless it's an ops requirement for some reason, I would absolutely recommend against the split. It's just all-hassle-no-gain. > Is there a way to use shadow-cljs to proxy the api requests to my backend server? Shadow-cljs is a built too. Why would you want to use a build tool for proxying requests?
I guess the reason is a built in server in shadow that serves static assets in dev, handles hot reloading and REPL connection
Hot reloading and REPL are unrelated to HTTP requests and don't require anything special, regardless of the setup (that is, unless you develop on a host other than localhost). IMO as soon as one's needs go beyond the most basic dev stuff, the built-in shadow-cljs web server should be replaced with something else.
Here’s related docs section https://shadow-cljs.github.io/docs/UsersGuide.html#proxy-support but I’d post the question in #shadow-cljs
I'd second just using your backend server to serve the output .js files. they are just static files and the server doesn't need to do anything special.
https://shadow-cljs.github.io/docs/UsersGuide.html#dev-http-proxy is actually the correct link @roman01la :devtools-url is something else
Not sure if this still holds, but at least this is how I proxied every requests that started with /api to the backend server in a project of mine a few years back:
;; shadow-cljs.edn
:dev-http {8000 {:proxy-url ""
:proxy-predicate foo.client.dev-support/proxy-predicate
,,,}}
;; dev_support.clj
(ns foo.client.dev-support
(:require [clojure.string :as string]))
(defn proxy-predicate [ex config]
(string/starts-with? (.getRequestPath ex) "/api")) sure that still works. Just seems easier to just have localhost:9000 serve the .js files 🤷