This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-06
Channels
- # announcements (2)
- # babashka (22)
- # beginners (93)
- # calva (12)
- # cider (65)
- # clj-kondo (15)
- # cljdoc (5)
- # cljs-dev (4)
- # cljsrn (4)
- # clojure (65)
- # clojure-europe (2)
- # clojure-italy (1)
- # clojure-nl (1)
- # clojure-norway (1)
- # clojure-spec (40)
- # clojure-uk (7)
- # clojurescript (12)
- # conjure (1)
- # cursive (2)
- # data-science (13)
- # datomic (1)
- # dirac (12)
- # emacs (3)
- # figwheel-main (19)
- # ghostwheel (5)
- # helix (6)
- # kaocha (1)
- # leiningen (6)
- # news-and-articles (2)
- # off-topic (17)
- # pathom (5)
- # re-frame (59)
- # reitit (17)
- # restql (1)
- # shadow-cljs (31)
- # spacemacs (5)
- # spire (3)
- # sql (35)
I want to serve static files from a directory on disk in my dev environment (in production I use a CDN). Is there a recommended method of doing this with Reitit? I noticed https://metosin.github.io/reitit/ring/static.html has “serve from file-system” as a TODO item, so I assume I’ll have to find some other approach.
@wombawomba I’ve done something like this
["/index.html"
{:get
{:no-doc true
:handler
(fn [_]
{:status 200
:headers {"Content-Type" "text/html"}
:body (io/input-stream (io/resource "public/index.html"))})}}]
Where io
refers to
Another option is to simply fire up a Jetty server from REPL to serve static files during development. I’ve done just that here https://github.com/ClojureFinland/ClojureFinland.github.io/blob/new-start/dev/server.clj
You need to add org.eclipse.jetty/jetty-server {:mvn/version "9.4.29.v20200521"}
to your dev-depencencies
I’m struggling with how to use this. It seems like if I don’t specify :root
every request results in a NPE.
And when I do specify :root
, I can’t figure out how to get it to find my files (everything seems to cause a 404
).
Are there any examples for how to use it?
or alternatively, how would I use it to just serve a directory?
Alright, I was able to make it work now by using the “Internal routes” approach from https://metosin.github.io/reitit/ring/static.html instead of the “External routes” one
I think either I’m misunderstanding how the the “External routes” approach is meant to work, or something isn’t working quite right..
Alright, I figured it out. I needed to provide both :root
and :path
when using the external routes approach. Perhaps the docstring could be rephrased to make it more clear which arguments are required in which situations?
Also, :root
defaulting to public
seems pretty counterintuitive/surprising to me.. Wouldn’t it make more sense to just force the user to supply :root
instead? Feels like it would be better to avoid making these kinds of implicit assumptions about the user’s file structure/intentions.
Oh and another idea, perhaps there should be some sort of validation to check if the root
path actually exists?
Hey friends, before I log an issue, I wanted to confirm it here first. While using reitit.frontend.easy/start!
I noticed that when you trigger an HMR reload with something like figwheel the event listeners are not being removed when the stop
method is run. This seems to be because :listen-key
and :click-listen-key
are not set.
Assuming this is not based on how I have this configured my app, I believe I have narrowed the issue down to https://github.com/metosin/reitit/blob/master/modules/reitit-frontend/src/reitit/frontend/easy.cljs#L38. My thinking is that when we reset the history
atom to the version of this
(the history
record) we are currently resetting to does not have the event-listener keys as the on-navigate
is called in https://github.com/metosin/reitit/blob/master/modules/reitit-frontend/src/reitit/frontend/history.cljs#L119.
I cloned the repo locally and implemented a change based on the investigation above and it seems to resolve the issue. Let me know what ya’ll think and I would be happy to log an issue and even make a PR of the fix I implemented.