This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-28
Channels
- # asami (13)
- # babashka (6)
- # beginners (38)
- # calva (14)
- # cider (15)
- # circleci (13)
- # clj-kondo (4)
- # cljsrn (18)
- # clojure (164)
- # clojure-bay-area (3)
- # clojure-europe (46)
- # clojure-italy (8)
- # clojure-losangeles (3)
- # clojure-norway (3)
- # clojure-sweden (24)
- # clojure-uk (115)
- # clojurescript (79)
- # cursive (11)
- # datomic (24)
- # docker (2)
- # events (9)
- # figwheel-main (31)
- # fulcro (5)
- # honeysql (6)
- # jackdaw (7)
- # jobs (3)
- # jobs-discuss (16)
- # joker (1)
- # kaocha (6)
- # keechma (1)
- # lein-figwheel (1)
- # malli (6)
- # pathom (10)
- # podcasts-discuss (13)
- # practicalli (3)
- # react (4)
- # reagent (3)
- # reitit (8)
- # remote-jobs (3)
- # shadow-cljs (21)
- # sql (12)
- # tools-deps (20)
- # xtdb (24)
Hi, so I'm new to clojurescript, and I like the leiningen figwheel-main template, but I'd like to deploy to Heroku. I think Heroku sets the port via a PORT environment variable. Is there a way to make an application created with the figwheel-main template use the PORT environment variable instead of the :port
in :ring-server-options
. The documentation mentions that if you find yourself using the :ring-server-options
"you probably need to run your own server outside of figwheel.main". Maybe that's what I need to do. Does anyone have any good examples of how to do that? Thanks!
@badchicken2 Do you actually have a server-side piece to your app or is it pure cljs?
(I haven’t used lein
for years so I can’t help you with that — I’ve only used figwheel-main
via the Clojure CLI/`deps.edn`)
I'm going to have a server-side piece. I'm open to using something besides lein, but basically I want clojurescript/reagent in the UI with clojure server-side, plus figwheel watching/reloading changes during development... and deployable to Heroku. I've spent a lot of time looking at different options, but nothing seems to be quite what I'm looking for. It's pretty confusing as a beginner.
@badchicken2 You can check here https://github.com/prestancedesign/todo-backend-clojure-reitit/blob/master/src/todo_backend/core.clj#L72.
This is how you can do.
FYI, this todo app example run on Heroku. Check also the Procfile
used by Heroku
to run the JAR version of your app. https://github.com/prestancedesign/todo-backend-clojure-reitit/blob/master/Procfile
Hope this can help.
> The documentation mentions that if you find yourself using the :ring-server-options
"you
> probably need to run your own server outside of figwheel.main". Maybe
> that's what I need to do. Does anyone have any good examples of how to
> do that?
This is what your need https://github.com/bhauman/figwheel-main/blob/ead06b94b1b2747ed37e5d8c37118d6e7ae77193/docs/docs/your_own_server.md
Thanks for the link. On the page it says "If you don't already have a host page for your application and you are not sure how to create one, please see the documentation on this subject", but the links are broken so I'm not sure what I need to do with that. What is a host page?
Here is the working link: https://github.com/bhauman/figwheel-main/blob/master/docs/docs/your_own_page.md
I'll do a PR to fix the document, the *.md
extension is missing.
Following the instructions from your_own_server.md
results in an error when I try to run it: "java.io.FileNotFoundException: Could not locate ring/adapter/jetty__init.class, ring/adapter/jetty.clj or ring/adapter/jetty.cljc on classpath".
You should put Ring in your dependencies https://github.com/ring-clojure/ring
[ring/ring "1.9.3"]
I'll take a look at figwheel-heroku
. Adding ring to the dependencies didn't help.
Also, this problem happens whether I created the project with lein
or with clj
(using the examples on https://github.com/bhauman/figwheel-main-template)
Are your restart the REPL after the dependencie update?
Did you had ring/ring
not only ring/ring-core
?
Ring-core doesn't contains ring.adapter.jetty
server
I did. Here's an example of what I'm doing.
OK I see, the Figwheel doc is incomplete.
With the scripts/server.cljs
example, you need more dependencies:
{:deps {org.clojure/clojure {:mvn/version "1.10.0"}
org.clojure/clojurescript {:mvn/version "1.10.773"}
ring/ring {:mvn/version "1.9.3"}
ring/ring-defaults {:mvn/version "0.3.2"}
com.bhauman/figwheel-main {:mvn/version "0.2.13"}
com.bhauman/rebel-readline-cljs {:mvn/version "0.1.4"}
reagent {:mvn/version "0.10.0" }}
:paths ["src" "resources" "target"]
:aliases {:fig {:extra-deps
{com.bhauman/rebel-readline-cljs {:mvn/version "0.1.4"}
com.bhauman/figwheel-main {:mvn/version "0.2.11"}}
:extra-paths ["target" "test"]}
:build {:main-opts ["-m" "figwheel.main" "-b" "dev" "-r"]}
:min {:main-opts ["-m" "figwheel.main" "-O" "advanced" "-bo" "dev"]}
:test {:main-opts ["-m" "figwheel.main" "-co" "test.cljs.edn" "-m" "yourname.test-runner"]}}}
Hey, that worked! I also added "test" to the :paths
to quell a warning. Thank you so much for all your help!
This is one area that I think the Clojure ecosystem could use some improvement. There are so many different examples of how to cobble together an app and development environment, some of which don't quite work as described. It's challenging if you're new to Clojure.
You're welcome! Glad to know that works.
Yes I agree, there are room to some improvements here. The learning curve is steep at the beginning but once that is over it is much smoother. I think that at the moment there is a good progression on the resources (tutorials, articles, etc).
Take a look at this template, it should help you: https://github.com/kliph/figwheel-heroku
@badchicken2 What you want is roughly a scheme like this
Figwheel runs as a server on port X. It watches your source directory and moves compiled artifacts to some directory /js/path
this server includes all your api endpoints, features, and serves the javascript stored in /js/path when requested
you open your web browser to the server running on port Y, which serves some html that includes the "root" js stored at /js/path
when the code loads, it will look for port X and connect to the figwheel server running there