Fork me on GitHub
#re-frame
<
2021-02-10
>
zach20:02:19

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.

manutter5120:02:57

I don’t think I’ve heard of the +handler extra, what is that?

zach20:02:25

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"))

manutter5120:02:18

Oh, it’s a luminus thing. Gotcha, that makes sense now.

manutter5120:02:36

or not luminus, re-frame itself I guess?

zach21:02:30

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.

manutter5121:02:37

Ok, re-reading your original post, that should have been clear to me. (Long day 😛 )

zach21:02:01

(haha, no worries!)

manutter5121:02:33

Ok, so how are you hitting that /api endpoint?

manutter5121:02:49

Are you making an ajax call from the browser or just going to it directly?

manutter5121:02:11

Actually, I should back up and review my compojure stuff, just a sec

zach21:02:26

ah, good question! I am just visiting it in the browser.

dpsutton21:02:48

evaluate (not-found "Page not found") returns. i think you need a bit more structure than you're giving there

👍 3
manutter5121:02:56

We’ve switched to reitit and now my compojure-foo is rusty.

manutter5121:02:43

If you haven’t done so already.

manutter5121:02:12

I.e. just start up a toy compojure project, without re-frame, and see how you get on with that.

dpsutton21:02:47

((route/not-found "not here!") :dummy)
{:status 404,
 :headers {"Content-Type" "text/html; charset=utf-8"},
 :body "not here!"}

manutter5121:02:50

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.

zach21:02:13

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?)

manutter5121:02:06

I’m running two repls, server and browser. I started from a different template tho.

zach21:02:19

Is there a template you recommend for studying?

manutter5121:02:22

I’d say start with the compojure one, get compojure working, then do the re-frame one, should get your feet off the ground.

zach21:02:16

Sweet, thank you!

mikethompson23:02:29

@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

👍 4