Fork me on GitHub
#boot
<
2016-03-10
>
seancorfield01:03:04

FYI, I’m going to refactor boot-new so it more closely matches the structure of boot/core so it’ll be easier to merge in https://github.com/seancorfield/boot-new/issues/15

seancorfield01:03:15

Feedback from Boot contributors welcome!

seancorfield03:03:31

OK PR #428 passes the build now. If I get time, I’ll look at how to write tests for the boot new stuff and integrate those as well (but I won’t have much time for that before the middle of next week — I only pushed on the integration PR today since @micha indicated he was going to attack the PRs this weekend simple_smile )

bendy05:03:42

Hey all, I’m trying to write a simple clojure app using boot & compojure. I can’t seem to boot up the server though - I’m sure it’s something simple

bendy05:03:57

I have these two files: build.boot:

(set-env!
  :source-paths #{"src"}
  :resource-paths #{"resources"}
  :dependencies '[[org.clojure/clojure "1.8.0"]
                  [ring-server "0.4.0"]
                  [compojure "1.5.0"]
                  [pandeiro/boot-http "0.7.3" :scope "test"]])

(require '[pandeiro.boot-http :refer :all])
(require '[produce.api :as api])

(deftask dev []
  (comp
    (serve :handler ‘api/handler
           :reload true
           :init 'api/init)
    (wait)))
src/produce/api.clj
(ns produce.api
  (:require [compojure.core :refer :all]))

(defroutes api
  (GET "/greeting" []
       "Hey!"))

(def handler api)

(defn init []
  (println "initializing api"))

bendy05:03:12

Yet when I run boot dev I get the error:

Could not locate api__init.class or api.clj on classpath.

bendy05:03:40

It does however run produce.api/init

bendy05:03:24

Can anyone spot what I’m doing wrong? If I run serve with no options, it doesn’t error, but that’s not super helpful 😉

bendy05:03:58

Oh, facepalm - it does not run produce.api/init, I was declaring the function incorrectly. Even after fixing the declaration I still get the same issue

seancorfield05:03:06

Use the full symbol names in the serve call: 'produce.api/api and 'product.api/init

seancorfield05:03:41

The handler and init values are resolved in a context that doesn't have the require alias.

bendy05:03:59

Well, that did it

bendy05:03:04

thanks! haha

bendy05:03:52

I had tried that but at the time my init function was being declared as a var not a function

bendy05:03:40

I’d rather not admit how long I’ve spent trying to work this out…

seancorfield05:03:09

FWIW, you don't need the require for produce.api at all in build.boot

bendy05:03:48

gotchya - so it was erring because the quoting the name doesn't use aliases? Or was I requiring & aliasing it wrong?

bendy05:03:35

(not sure the clojure term for :as - that’s what I mean when I say aliasing)

seancorfield05:03:05

Because 'foo/bar is just a symbol -- it evaluates to itself.

seancorfield05:03:47

So you don't need a require in build.boot to reference it at all. You're just passing arbitrary symbols to the serve task... which in turn resolves them in its own namespace.

bendy05:03:45

ok, cool, that makes sense

bendy05:03:49

followup question: do I need to pull in ring-server as a dependency? Or does boot-http come with one?

bendy05:03:28

(I’m pretty much just going entirely off of those github repo, as it was the only example I could find that defined a dev task: https://github.com/borkdude/lein2boot)

seancorfield05:03:44

I'm not familiar with boot-http so I'd have to try it and see (I tried out your code to figure out that first issue).

seancorfield05:03:22

Commenting out the Ring server dependency doesn't break things so I guess you don't need it as a specific dependency.

bendy05:03:34

Well I took it out and it still runs…. So I’m going to assume it’s not necessary. I thought it seemed extraneous, but I’m too new too all these libraries to make many assumptions

seancorfield05:03:52

You do need compojure tho'

smw05:03:28

Is anyone aware of an example (or boot task/library) to run the agent for dirac devtools?

bendy05:03:52

I guess the reason I asked was I’m not to sure how dependencies work. I know when I add them, and run boot, it will install them. If I take them out, does it remove them? Remove them from the class-path? Or do I need to manually remove it via the cli?

seancorfield06:03:46

Dependencies are transitive. So if pandeiro.boot-http has its own dependency on ring-server, it will be pulled in if you depend on pandeiro.boot-http

seancorfield06:03:18

Those dependencies are downloaded (once) and stashed locally (in your ~/.m2/repository cache).

seancorfield06:03:04

Boot figures out the full dependency tree based on what you explicitly declare and downloads anything that is missing and then builds a classpath with all of the dependencies on it, then runs stuff.

bendy06:03:43

ah perfect

seancorfield06:03:38

If you want a different version of ring-server, you can declare that explicitly and then when you declare the pandeiro.boot-http dependency, you can exclude ring-server -- then you won't get that transitive version, you'll get your explicit version.

bendy06:03:52

This is my first web-related clojure project, so sorry if these questions are painstakingly simple simple_smile

seancorfield06:03:30

Don't worry, the whole fun world of dependency management is something that you slowly get used to as you build bigger things with Clojure...

bendy06:03:11

Yeah I’m expecting it to be a bundle of fun

bendy06:03:25

(pun intended)

seancorfield06:03:21

I use a "framework" of my own design for web apps -- it's essentially a bundle of Ring and Selmer (for web pages) and some dynamic routing logic -- so if you you ask for /greeting it will look for app.controllers.greeting/default and run that as a handler... if you ask for /greeting/hello it will look for app.controllers.greeting/hello and run that.

seancorfield06:03:55

It's based on an MVC framework I built in 2009 for CFML and I ported it to Clojure a few years back.

bendy06:03:46

Is it open source? 😄

bendy06:03:57

I’d be curious to see how you wrote it

seancorfield06:03:19

There's a Boot template for new apps too.

bendy06:03:37

Yeah I saw you were working on boot-new

bendy06:03:14

I’m trying to avoid using any templated solutions for now because I obviously need to learn my fundamentals first

bendy06:03:29

but it looks like an awesome project that I’ll use once I know what I’m doing

bendy06:03:53

I’ll definitely look through fw1-clj though, thanks for that link

seancorfield06:03:55

Feel free to ping me with my any questions -- DM if you want -- we've been using the CFML version in heavy production use for quite a while and we're transitioning to the Clojure version at the moment.

seancorfield20:03:57

Hey @micha I sent a PR for boot-new integration for consideration for 2.6.0 but wanted to let you know I’ll be AFK over the weekend, in case you have any questions and ping me … and I don’t seem to answer!

micha20:03:29

@seancorfield: awesome, i'll check it out tonight before the weekend

smw22:03:02

Hey boot people! I’ve been playing around with dirac (https://github.com/binaryage/dirac) which does some really cool experimental things with chrome devtools.

smw22:03:23

One of the cool things it does is to let you have a cljs repl inside devtools.

smw22:03:04

To do that, it runs an ‘agent’ — basically a proxy — that lets the forked devtools talk to the nrepl.

smw22:03:14

And, I had a question, but someone just answered it for me. Was going to get a PR to integrate Dirac into boot-cljs-repl, but it looks like just replacing boot-cljs-repl with dirac is only a few lines of code.