This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-06
Channels
- # aleph (13)
- # announcements (1)
- # babashka (89)
- # beginners (23)
- # calva (14)
- # circleci (7)
- # clj-kondo (39)
- # clj-on-windows (1)
- # cljdoc (5)
- # cljsrn (29)
- # clojure (98)
- # clojure-art (3)
- # clojure-conj (5)
- # clojure-europe (14)
- # clojure-nl (1)
- # clojure-norway (9)
- # clojurescript (18)
- # clr (39)
- # code-art (3)
- # community-development (3)
- # cursive (3)
- # emacs (11)
- # events (1)
- # fulcro (12)
- # graalvm-mobile (16)
- # graphql (3)
- # gratitude (1)
- # honeysql (19)
- # java (7)
- # joyride (23)
- # lsp (22)
- # malli (2)
- # missionary (25)
- # off-topic (15)
- # polylith (15)
- # rdf (5)
- # reagent (9)
- # reitit (3)
- # scittle (3)
- # shadow-cljs (37)
- # slack-help (2)
- # sql (10)
Hello. I need to have a config.edn that will work both for backend and for frontend compile constants. What’s the ideal way to achieve this with shadow-cljs?
For example: • wether the app is compiled in debug mode or not • the links the app will point too (different across dev/prod environments) They need to be in a config.edn because both the backend and frontend need to access them, and different environment have different config files.
and usually that is something my backend sends to my frontend, usually directly with the initial HTML
Yeah you’re right, for the backend it’s runtime configuration
I guess I could send it to the frontend, yes
but it’d be more practical having it directly compiled into the js file imo.
for that you just need to build your own solution. since there is nothing provided out of the box for that
I guess I could have shadow cljs to read the config.edn file and then generate closure defines according to it
https://shadow-cljs.github.io/docs/UsersGuide.html#_release_specific_vs_development_configuration
Thank you!
I'd say its easier and more flexible by other means. for example not having the recompile the entire CLJS code if your backend url changes. or using the same frontend build for prod and testing
Hi, I’m a beginner in shadow-cljs and when it comes to familiarity with clojure and clojurescript, basically too. So please be patient :)
I have successfully launched a small one-page interactive application on shadow-cljs/reagent/firebase as a sort of proof-of-concept. So I am not completely stupid.
But now I’m stuck. I’m trying to figure out how to get the server (localhost for now) to simply take the address URI (e.g. the “a” part from localhost:8600/a
) that user entered into the browser + just dump it to my console (e.g. directly via handler function). The next step will be that I will generate additional URIs (subaddresses) based on the app’s interaction with the user etc. For now console reaction would be great. But I just get 200 OK response when entering localhost:8600/a into browser (or when contacting server via GET API) – still without any reaction from handler function.
The app is barebones, it compiles, the server runs, the page renders and is displayed. But when I specify e.g. localhost:8600/a
, I am unable to get the server to get the handler react. I run it using shadow-cljs watch app
.
Here is my shadow-cljs.edn setup:
;; shadow-cljs configuration
{:source-paths
["src"]
:dependencies [[binaryage/devtools "1.0.6"]
[reagent "0.8.0-alpha2"]
[ring "1.9.6"]]
:nrepl {:port 8777}
:builds
{:app {:target :browser
:output-dir "public/js/compiled"
:asset-path "/js/compiled"
:modules
{:main
{:entries [when.core]}}
:devtools
;; before live-reloading any code call this function
{:before-load when.core/stop
;; after live-reloading finishes call this function
:after-load when.core/start
;; serve the public directory over http at port 8700
:http-root "public"
:http-port 8600
:ring-handler when.helpers/handler
:preloads [devtools.preload]}}}}
What I am doing wrong here?
Thank you very much!shadow-cljs is a CLJS development tool. ring is CLJ server side, which I always recommend doing without shadow-cljs
since you won't be using shadow-cljs in production either. it is best to just setup your own CLJ server. the CLJS setup doesn't change
if you really want to use shadow-cljs for this then you need to use the correct http config. https://shadow-cljs.github.io/docs/UsersGuide.html#dev-http
so just :dev-http {8600 {:root "public" :handler when.helpers/handler}}
at the top level. not inside the build config, and removing the http related things from there
Oh, now I understand. Thank you very much, Thomas and thank you for your great tool.
I updated the .edn to
;; shadow-cljs configuration
{:source-paths
["src"]
:dependencies [[binaryage/devtools "1.0.6"]
[reagent "0.8.0-alpha2"]]
:nrepl {:port 8777}
:dev-http {8600
{:root "public"
:handler when.helpers/handler}}
:builds
{:app {:target :browser
:output-dir "public/js/compiled"
:asset-path "/js/compiled"
:modules
{:main
{:entries [when.core]}}
:devtools
{:before-load when.core/stop
:after-load when.core/start
:preloads [devtools.preload]}}}}
and I get:
:shadow.cljs.devtools.server.dev-http/handler-load-ex - {:http-handler when.helpers/handler}
FileNotFoundException Could not locate when/helpers__init.class, when/helpers.clj or when/helpers.cljc on classpath.
...
[:app] Build failure:
The required namespace "when.helpers" is not available, it was required by "when/core.cljs".
"when/helpers.clj" was found on the classpath. Should this be a .cljs file?
during compilation.And here is my when.helpers file:
as I said. server side ring handlers are running in CLJ thus this needs to be a .clj
file not .cljs