This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-04
Channels
- # architecture (5)
- # aws (11)
- # aws-lambda (1)
- # beginners (108)
- # boot (11)
- # cider (37)
- # clara (19)
- # cljsrn (72)
- # clojure (170)
- # clojure-austin (2)
- # clojure-dev (1)
- # clojure-dusseldorf (2)
- # clojure-italy (1)
- # clojure-spec (41)
- # clojure-uk (24)
- # clojurescript (113)
- # component (2)
- # core-async (29)
- # cursive (9)
- # data-science (5)
- # datomic (72)
- # docs (23)
- # duct (61)
- # editors (1)
- # emacs (1)
- # events (5)
- # fulcro (77)
- # graphql (2)
- # hoplon (4)
- # jobs (3)
- # jobs-discuss (16)
- # leiningen (5)
- # off-topic (94)
- # onyx (37)
- # precept (5)
- # re-frame (17)
- # reagent (11)
- # shadow-cljs (18)
- # spacemacs (107)
- # specter (3)
- # unrepl (64)
- # yada (1)
there is usage here https://github.com/duct-framework/logger#usage
Thanks. The problem I had was that I should have refered to`#ig/ref :duct.logger/timbre` instead of #ig/ref :duct.module/logging
in my app handler
many thanks
how do I tell ataraxy to use :duct.module.web/api
for some route and :duct.module.web/site
for the rest?
I think it's not supported yet, you may have to add list of middlewares by yourself to ataraxy route config
Hi Folks, any idea how can I automatically have (reset)
run on file changes? e.g. how to configure file watch so it resets the duct for me?
@lambder You can use something like Hawk (https://github.com/wkf/hawk)
(hawk/watch! [{:paths ["src" "test"] :handler (fn [_ _] (reset))}])
thanks @weavejester
However, I’d recommend tying the (reset)
into your editor. If you’re using Emacs, Vim, Atom or Cursive there are inbuilt ways to bind a key to run a Clojure command.
@weavejester figwheel doesn't reload when cljs files change unless (reset)
. Is that expected?
@myguidingstar Yes, that’s right. It’s a deliberate design decision, since it allows you to save and reload in two separate steps.
So in Emacs, I have a key combination that saves, and a key combination that saves and reloads.
Having it automatically reload without any way of stopping it was problematic to me.
There are some changes that persist across multiple files - like changing the way the server and client communicate.
However, because people ask about it so much, maybe I’ll add a hawk command by default, so you can run something like (watch)
and it’ll automatically reload.
(defn watch []
(hawk/watch! [{:paths ["src" "test"] :handler (fn [_ _] (reset))}]))
Putting that in your dev.clj
file should mean you can type (watch)
and then have it reload automatically.
how do I use different middlware sets for different request handlers in ataraxy?
You can apply the middleware to the handlers manually, or via Ataraxy’s metadata syntax.
So with Ataraxy, you can do something like:
{:duct.core/project-ns :foo
:duct.module/ataraxy {"/foo" ^:bar [:baz]}
:foo.middleware/bar {}
:foo.handler/baz {}}
Metadata keys in the routes are treated as hints for middleware. So the metadata hint ^:bar
gets given the middleware from the key :foo.middleware/bar
Alternatively, you can add middleware manually:
yeah, the traditional ring way
(defmethod ig/init-key :foo.handler/baz [_ opts]
(wrap-baz (fn [req] ...)))
Since the key returns a handler, you can wrap it in whatever middleware you want.
Finally, you can also add global middleware to :duct.core/handler
under the :middleware
key.
hmm, say I want :duct.module.web/site
for everything except /api
which should be only wrapped by :duct.module.web/api
what's the best way to config that?
@myguidingstar The difference is in what middleware is supplied. The most straightforward way is to use :duct.module.web/site
and then add the :duct.middleware.web/format
middleware to the :duct.core/handler
key.
So like:
:duct.module.web/site {}
:duct.core/handler {:middleware [#ig/ref :duct.middleware.web/format]}
:duct.middleware.web/format {}
I intend to write a :duct.middle.web/site+api
module that does that for you, but I haven’t gotten around to it.
@weavejester the (watch) above throws this when files change java.lang.IllegalStateException: Can't change/establish root binding of: *ns* with set
What’s the stack trace? I guess Hawk does something weird?
java.lang.IllegalStateException: Can't change/establish root binding of: *ns* with set
at clojure.lang.Var.set(Var.java:223)
at clojure.lang.RT$1.invoke(RT.java:242)
at clojure.tools.namespace.repl$do_refresh.invokeStatic(repl.clj:95)
at clojure.tools.namespace.repl$do_refresh.invoke(repl.clj:83)
at clojure.tools.namespace.repl$refresh.invokeStatic(repl.clj:145)
at clojure.tools.namespace.repl$refresh.doInvoke(repl.clj:128)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at integrant.repl$reset.invokeStatic(repl.clj:52)
at integrant.repl$reset.invoke(repl.clj:50)
at dev$watch$fn__49177.invoke(dev.clj:40)
at hawk.core$process_handler$fn__32995.invoke(core.clj:41)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.AFn.applyTo(AFn.java:144)
at clojure.core$apply.invokeStatic(core.clj:657)
at clojure.core$apply.invoke(core.clj:652)
at hawk.core$catch_errors$fn__32968.doInvoke(core.clj:8)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.core$binding_conveyor_fn$fn__5476.invoke(core.clj:2028)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at clojure.lang.Agent$Action.doRun(Agent.java:114)
at clojure.lang.Agent$Action.run(Agent.java:163)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
btw, I'm looking at duct.module.web
source code. What are those :fn
and :req
in:
(defmethod ig/init-key ::site [_ options]
{:req #{:duct/logger}
:fn #(apply-web-module % options (site-config (get-project-ns % options)))})
The :fn
is the function - it transforms the configuration. The :req
is the required keys - that’s used for ordering.
so it mutates current config?
It looks like there’s some weird interaction between Hawk and tools.namespace. I’m not sure how to solve it right now, but I’ll take a look when I get back off holiday. You could try using another file watcher (check http://clojure-toolbox.com).
It transforms the configuration. So in Duct there are three stages - read, prep, init
The config is read from the edn
Then prepped, where the modules transform the configuration
Then finally initiated.
interesting
The way modules work might change a little in future, though. The same idea will hold, but I think there’s a better way of doing them.
how do I start two http server with different ports?
Use composite keys:
[:duct.server.http/jetty :foo.server/web] {:port 3001}
[:duct.server.http/jetty :foo.server/api] {:port 3002}
But be aware that I don’t think the web modules will work with that, since they won’t know which server to use. You’ll need to add the keys in manually.
All modules do is just transform the configuration, adding new keys.
Without them, you need to add the keys in manually (or write your own module).
The web modules essentially just populate :duct.core/handler
, add a bunch of middleware, and that’s about it.
They can wire things up because they look for a single HTTP server. If there are multiple ones, it’s ambiguous.
You can print config
at the REPL to see the configuration after it’s been prepped.
thanks a lot
You’re welcome
I’m planning on making some changes to how modules work that should make them easier to reason about.