Hi, I was wondering if any folk had experience with running the re-frame template as full-stack (e.g. using the +handler extra). I am trying to make an app where there’s the main route, which would be an SPA powered by reframe, and an /api route, that has some calls made directly to the server. I can’t quite seem to make it work, though, and am unsure if I’m understanding that +handler extra correctly.
I don’t think I’ve heard of the +handler extra, what is that?
It adds compojure, so that the resulting app has both a clj/app and cljs/app namespace. With compojure, it setups the server and defines basic routing:
(defroutes routes
(GET "/" [] (resource-response "index.html" {:root "public"}))
(resources "/")
(not-found "Page not found"))
Oh, it’s a luminus thing. Gotcha, that makes sense now.
or not luminus, re-frame itself I guess?
And this is likely just me not getting a concept, but if i add the route (GET "/api" [] "api a go")
it just returns a blank page. It looks like it’s still trying to have re-frame handle the routing for this path and not be server-side.
Ok, re-reading your original post, that should have been clear to me. (Long day 😛 )
(haha, no worries!)
Ok, so how are you hitting that /api
endpoint?
Are you making an ajax call from the browser or just going to it directly?
Actually, I should back up and review my compojure stuff, just a sec
ah, good question! I am just visiting it in the browser.
evaluate (not-found "Page not found")
returns. i think you need a bit more structure than you're giving there
We’ve switched to reitit and now my compojure-foo is rusty.
You might want to have a look at https://github.com/weavejester/compojure/wiki/Getting-Started
If you haven’t done so already.
I.e. just start up a toy compojure project, without re-frame, and see how you get on with that.
((route/not-found "not here!") :dummy)
{:status 404,
:headers {"Content-Type" "text/html; charset=utf-8"},
:body "not here!"}
Compojure and re-frame fit together nicely, so once you’ve got the compojure side down I think you’ll have no problem putting the two together.
Ah, that’s a good idea. Thanks all! Yeah, I’m finding some of my confusion especially new…and should maybe step back from the template (for example: should I be running two repls with this template now, one for server and one for client?)
I’m running two repls, server and browser. I started from a different template tho.
Is there a template you recommend for studying?
I’d say start with the compojure one, get compojure working, then do the re-frame one, should get your feet off the ground.
Sweet, thank you!
@webmaster601 instead of using re-frame-template
, you might also want to use the templates used by luminus
... they are more backend focused. You can add +re-frame
to their templates