re-frame

https://github.com/Day8/re-frame/blob/master/docs/README.md https://github.com/Day8/re-frame/blob/master/docs/External-Resources.md
zach 2021-02-10T20:53:19.082100Z

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.

2021-02-10T20:54:57.082500Z

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

zach 2021-02-10T20:58:25.083900Z

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

2021-02-10T20:59:18.084500Z

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

2021-02-10T20:59:36.085Z

or not luminus, re-frame itself I guess?

zach 2021-02-10T21:00:30.086400Z

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.

2021-02-10T21:00:37.086600Z

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

zach 2021-02-10T21:01:01.087300Z

(haha, no worries!)

2021-02-10T21:01:33.088300Z

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

2021-02-10T21:01:49.088900Z

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

2021-02-10T21:02:11.089500Z

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

zach 2021-02-10T21:02:26.089800Z

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

dpsutton 2021-02-10T21:02:48.090500Z

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

👍 1
2021-02-10T21:02:56.090700Z

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

2021-02-10T21:04:34.091Z

You might want to have a look at https://github.com/weavejester/compojure/wiki/Getting-Started

2021-02-10T21:04:43.091200Z

If you haven’t done so already.

2021-02-10T21:05:12.091700Z

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

dpsutton 2021-02-10T21:05:47.092500Z

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

2021-02-10T21:05:50.092600Z

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.

zach 2021-02-10T21:07:13.093600Z

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

2021-02-10T21:08:06.094400Z

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

zach 2021-02-10T21:09:19.094600Z

Is there a template you recommend for studying?

2021-02-10T21:11:22.095500Z

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

zach 2021-02-10T21:12:16.095900Z

Sweet, thank you!

2021-02-10T23:27:29.097200Z

@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

👍 1