Fork me on GitHub
#clojurescript
<
2019-02-26
>
pwalsh09:02:32

Hi. I want to write a server with ClojureScript, running on Node. Basically, I want to be able to use Express or Hapi, other JS libraries such as ones for i18n, but do so using ClojureScript and Hiccups with a view to starting with server-side rendering, and over time doing more client side stuff (so integrating reagent etc later). Here is a nice example of doing something like this using shadow-cljs: https://github.com/lambdaisland/npmdemo/tree/master/shadow-cljs I wanted to check in here on the following: - There are not a lot of examples of a setup like this to be found googling - is anyone here running a similar server-side stack with ClojureScript in production? - Any gotchas with shadow-cljs, which I have not used before? Any other thoughts and shared experience would be helpful. I could also do this on the JVM, but I like the idea of sharing frontend/backend code in future iterations. Also, I need to use gettext, and there don't seem to be any Clojure libraries for that (I want to use .po files etc.), and I need things like unicode URIs which in a very quick check, don't work as expected in Compojure.

danielneal09:02:06

@vikeri came across an old question of yours asking about RSA in goog.crypt. Did you find anything? I'd like to use RSA in react native and I couldn't find anything in goog.crypt either...

vikeri06:02:31

@U051H1KL1 turns out rn doesn't support any native random number generator out of the box and thus a lot of vanilla js crypto libs don't work. I resorted to using react-native-libsodium which gets the job done. Didn't end up using RSA but I'm pretty sure libsodium supports it or possibly something better

danielneal08:02:51

ah cool thanks for that. I needed to use RSA for compatability with our payment provider. Ended up using their javascript sdk in a webview!

thheller09:02:07

@pwalsh most clojure devs use clojure on the server-side but there are a couple people using CLJS on the server-side (using shadow-cljs). happy to help if you have specific questions.

pwalsh09:02:34

@thheller at this stage the main thing is, how risky is it 🙂. Shadow CLJS looks very slick; I just don't know what I don't know. FWIW this is a pretty simple app - it gets data from a GraphQL endpoint and renders an ecommerce site, basically. Most of the business logic is on the API server which I wrote in Python.

thheller09:02:52

no risk at all I'd say. equal or less risky than the other options. 😉

thheller09:02:04

probably best to ask some people in #shadow-cljs. I'm a bit biased.

mhuebert09:02:30

@pwalsh I’ve been using ClojureScript for a node.js server (via shadow-cljs) and it’s been a great experience

pwalsh10:02:33

@mhuebert oh great to hear. any open code that I can peek at? Are you integrating with express, hapi, next.js or any other such framework?

mhuebert10:02:08

unfortunately that project isn’t open-source. I have been migrating an existing (2012-era) coffeescript app, gradually re-writing pieces of it in cljs

mhuebert10:02:23

it was/is written in express

mhuebert10:02:49

and i have been migrating it to a GraphQL api

mhuebert10:02:55

all written in cljs

pwalsh10:02:58

can I ask some more questions then 🙂

pwalsh10:02:56

- are you templating with hiccups? - is it a good REPL-driven development flow? - which GraphQL client are you using? - how is the compiled js, can you debug from the production js back to the class code? - are you doing any localisation or internationalisation?

mhuebert10:02:42

I haven’t been doing SSR yet, but I did need to generate some simple html files from cljs and I used a JS library for that, https://github.com/thi-ng/umbrella/tree/master/packages/hiccup - mainly because it is very fast and simple. When I do get to implementing SSR, it will be react-based, because that’s what my entire front-end is written in.

mhuebert10:02:02

I wrote my own GraphQL layer, intending to publish it, though I am not entirely sure if it’s something I want to support as an open-source project - I’ve been really interested in approaches like Pathom

mhuebert10:02:43

so i am actually writing my graphql queries in a hiccup-syntax which compiles to graphql queries

mhuebert10:02:30

i am doing some localisation but just using some small utils that I wrote, i plan on migrating to something more established

mhuebert10:02:52

should mention that the utils I wrote piggyback on “messageformat”

mhuebert10:02:06

at some point I had set up source-mapping with sentry (uploading source-maps there on deploy)

mhuebert10:02:21

so I could see correct locations of errors in prod

mhuebert10:02:03

my project is particularly complicated because it involves so much legacy code

mhuebert10:02:37

the eventual goal is to finish deleting all the legacy stuff and be 100% cljs, am at about 75% now

pwalsh11:02:43

@mhuebert great to hear all this, thank yo for sharing. I'm going to go for it 🙂

pwalsh11:02:11

I'm super interested in the hiccup > graphql stuff. Pity there is not an existing open source solution for that.

rakyi19:02:00

there is https://github.com/Vincit/venia and probably some others as well

👍 5
idiomancy14:02:56

Is there metadata about a function value that one can access in clojurescript? I'm putting the function that caused the exception in my error messages, and right now it prints the source of the function (which is awesome! much more than I hoped for) BUT I would also like to just get the name. Is that accessible in any form?

idiomancy14:02:29

I just want the cljs$core$first part!

thheller14:02:11

@idiomancy the name accessible via the .-name property on the fn but it will only be useful in development builds. :advanced optimized builds will strip that name or shorten it. and no there is no way to get other metadata about the function

idiomancy14:02:04

ahh, interesting that makes sense. Same will go for the source, I imagine

thheller14:02:28

source is always available, it just will make a lot less sense in :advanced 😉

idiomancy14:02:43

lol yeah. Thanks, theller!

ro618:02:33

@darwin Thanks for Chromex! I'm using chromex-sample to figure out my own WebExtension. Just wondering how deeply you dug into the content_script init issue under :optimizations :none (referenced here: https://github.com/binaryage/chromex-sample/blob/master/project.clj#L57). It looks to me like the assets are being loaded from the page domain, rather than the extension domain. I guess under :optimizations :advanced the issue is sidestepped since everything's in one .js file. Has anyone else used CLJS for a WebExtension content_script? Where can I learn more about how asset loading works under :optimizations :none?

john20:02:30

Yeah, so, it's doable but nontrivial @robert.mather.rmm. I've got an extension that injects a figwheel repl into any arbitrary webpage. I'll try to publish it tonight.

👍 5
ro620:02:01

Thank you sir, would love to see that.

john20:02:17

The only question I'm wondering about is whether or not to monetize it or not. Or to have an optional upgrade/donation button...

john20:02:44

Anyone have opinions on which way to go with that?

john20:02:44

I was thinking a 3 dollar monthly subscription, where 1 dollar goes to figwheel, 1 dollar goes to Clojurists Together, and 1 dollar goes to my project (and whoever is contributing to it)

jaide20:02:07

That sounds like a fair price. Would it be for commercial uses only or everyone?

john20:02:58

Not sure... But going that way, I could probably just, what, have a string somewhere saying "non-commercial version, click here to upgrade." And then just trust the user to upgrade if they're commercial?

john20:02:33

I'm not really interested in splitting out feature sets

jaide20:02:25

I think that’s how REBL does it right? It’s just stated in both the docs and its license that REBL is free for open source projects but you gotta have a datatomic or active paetron subscription to use it commercially.

john20:02:26

Honestly, I don't expect to get much beer out of a dollar a month subscription. For me, it's more about helping to normalize charge-models around open source software. So I'm generally fine with a "trusted upgrade" or donation model, or not charging anything at all. It's more-so an experiment for the principle of it.

john20:02:54

I believe so too

jaide20:02:52

That makes sense. What I like about the trusted upgrade approach is that it gives people the option to try it out on a personal, OSS side-project, get excited about it, then purchase it for work.

john20:02:55

Okay, I'll try to take that route first

5
john20:02:42

But if all the monetization bits prove to complicated, I'll probably just release a non-monetized version tonight, just to get it out the door, for people to play with - with a "trusted upgrade" versions soon to follow.

jaide20:02:56

That sounds like a good plan to me.

john21:02:26

BTW @jayzawrotny, I'll be using your template as inspiration for docs... The solution comes in two components: 1) the extension you install, and 2) a template that you run with lein new or clj -A:new which wraps figwheel's default template, with the extra configuration bits necessary to let the extension connect back to it. So your template docs are going to come in super handy as I build out that template, thanks!

jaide21:02:49

Cool, I look forward to trying that out. I don’t wish to impose but it may be helpful to start with an outline or mind-map, like I shared in our earlier thread, before writing. It’s surprising how much time that can save figuring out the right flow & organization.

john21:02:30

Yeah, thanks for that. I'll be using that to plot out my initial docs.

metal 5