Fork me on GitHub
#reagent
<
2016-12-10
>
cmal02:12:30

Hi, are there any working examples that using reagent + server routing in one project? I am currently working for a project that needs API relay in the reagent project. If I do not do API relay, there is a CORS problem when using APIs from another domain. What is the recommended way to do this? Are there any working examples? Or should I create a Ring server in the same project to do API relay? Thanks.

shaun-mahood03:12:49

@cmal: what do you mean by API relay? There are solutions for having ring and reagent in the same project and for separate projects and allowing CORS as well. Do you have a preference?

cmal03:12:46

@shaun-mahood I have to request APIs from server side other than browser because of CORS. So I try to solve this problem by trying to add a routing server in my frontend project. The constraint here is that I can only maintain one project to do the job. Thanks.

shaun-mahood03:12:13

@cmal: Ok, 2 options you could check out are Luminus ( http://www.luminusweb.net ) and chestnut ( https://github.com/plexus/chestnut ) - both have front end and back end in a singlw project. I think you can also do it with a new reagent template ( https://github.com/reagent-project/reagent-template/ ).

cmal04:12:56

@shaun-mahood Thanks. I will dive into chestnut for some ideas. I currently use re-frame in the frontend project and try to connect to a mongo db backend server and/or its APIs.

cmal04:12:10

The reagent-template is also a great idea. I'll try to learn something from this.

ryancole04:12:21

Hi, folks. A beginner here. I was trying to whip together a simple proof of concept of server rendered reagent. I had started with an actual clojure app, using http-kit, with the intention of using reagent's server utils (`render-to-string`). I quickly realized that reagent is clojurescript (duh) and cannot be used via clojure directly.

ryancole04:12:41

Since these server util functions are clojurescript, does this mean there's an approach to running clojurescript on the server? Or can reagent work with clojure? I saw the cookbook, using nashorn, but if that's what it takes I think I may just prefer to stick with my current node version of this project.

ryancole04:12:25

My clojure demo is like a basic 10 liner. Is there something comparable in clojurescript?

terje04:12:09

@ryancole You can use server-side render-to-string with clojurescript on node. See: https://github.com/TerjeNorderhaug/cljsnode

ryancole04:12:21

@terje OK, that's kind of where I was heading next. So, now I'd no longer be running a JVM Clojure, on the server, I'd be running Node ClojureScript, correct? Which means my dependencies would no longer be Clojure (JVM) they'd be from the NPM world (JS)?

ryancole04:12:41

I'd be essentially writing a Node app, but using a CLJS compiler. Correct?

ryancole04:12:06

(similar to perhaps coffeescript, typescript, etc)

terje04:12:38

Right. If you still need Clojure/JVM functionality consider an architecture with a cljs/node front-end server and a clojure/jvm back-end server.

ryancole04:12:30

Issue is that one little requirement of performing server rendering of React. 😕

ryancole05:12:08

I'm not against CLJS on server. The current implement of this application I'm contemplating converting to Clojure is in plain node.

ryancole05:12:40

I'd be familiar with the modules, etc. I can just already imagine issues where interop is kind of wonky, or there lacks CLJS wrappers, etc.

gadfly36105:12:50

I havent played with this yet, but seems possibly relevant: http://yogthos.net/posts/2016-11-30-Macchiato.html

terje05:12:05

A benefit of using cljs on node is better ability to share code between browser app and server.

ryancole05:12:51

Yea, I totally agree there. I'm just wondering if there's an annoyance of having to locate wrappers for various javascript modules, etc.

ryancole05:12:14

Or use the interop, which might have conflicting usage patterns, etc.

ryancole05:12:22

I don't know. I'll just have to find out. 🙂

yogthos05:12:28

@ryancole I'm finding interop is usually not too hard to wrap up, and I'm hoping to get some official wrappers for stuff like db drivers

yogthos05:12:02

most of the core stuff is cljs though, I'm using mount for state, but you could use component as well, bidi for routing, and timbre for logging

yogthos05:12:18

most of ring core and the middleware has been ported over now as well

yogthos05:12:43

the template even sets up a test harness now out of the box

yogthos05:12:35

that said it is all very new, so there are bugs and rough edges 🙂