Fork me on GitHub
#clojurescript
<
2019-03-05
>
Nazral01:03:54

I have a problem with cljs-http, the following request works fine: > curl -XPOST http://localhost:3000/save_annotations -H "Content-Type: application/json" --data "@resources/test/request_test.json" but this code

(defn ^:export save-annotations
  []
  (go (let [results (.getElementsByClassName js/document (name "res"))
            response (<! (http/post "/save_annotations" {:post-params {:key1 "value1" :key2 "value2"}}))]
        (prn reponse))))
returns this > XML Parsing Error: syntax error > Location: http://localhost:3000/save_annotations > Line Number 1, Column 1:

Nazral02:03:28

(the /save_annotations route simply replies "hello" so it shouldn't matter)

Nazral02:03:36

Ok it's working using cljs-ajax

kah0ona09:03:03

hello! I have a regex, that works in clojure, but if I evaluate it in clojurescript i get an error: #"<\/span>" cljs error : #object[SyntaxError SyntaxError: invalid regular expression flag s], which is a :js-eval-exception

kah0ona09:03:50

i eval this from CIDER, haven’t tried it in browser yet though

thheller09:03:34

regexp uses the underlying platform and there are differences between JVM and JS

kah0ona09:03:15

yeah but normal JS accepts this regex: /<\/span>/

kah0ona09:03:17

in my firefox console:
var re = /<\/span>/; //undefined
re.test("</span>"); // true

borkdude10:03:25

@kah0ona This works in KLIPSE:

(def r #"<\/span>")
(re-find r "</span>")
http://app.klipse.tech/

borkdude10:03:06

it also works in Planck REPL:

cljs.user=> (re-find #"<\/span>" "</span>")
"</span>"

borkdude10:03:51

however, when I put it in some compiled CLJS source, I get an error also

borkdude10:03:15

so might be a bug in CLJS

kah0ona10:03:23

both chrome and firefox yield this problem

kah0ona10:03:39

this project is on 1.10.439 cljs

kah0ona10:03:28

for now i hack a quick work-around

kah0ona10:03:57

and then i’ll see if i can submit it as an issue

borkdude10:03:16

this also works in a REPL, but not in the source: (re-find (js/RegExp. "</span>") "</span>")

kah0ona10:03:28

thanks for the help in the digging

borkdude10:03:13

oh wait, I was in a CLJC file. This works: #?(:cljs (println (re-find (js/RegExp. “</span>“) “</span>“)))

borkdude10:03:43

I think your problem is that you don’t have to escape slashes:

(println (re-find #"</span>" "</span>"))

borkdude10:03:52

so probably not a bug after all

kah0ona10:03:54

my regex lives in a cljc file as well

borkdude10:03:40

yeah, that doesn’t matter, it works in both clojure and CLJS

kah0ona10:03:30

yep ok got it working, indeed, didn’t need to escape the /

dpsutton19:03:46

Trying to set up a docker file to run clojurescript by shadow-cljs for some friends who might not have java installed. Does anyone have an example doing this? Trying to figure out how to mount the source directories so it can live reload and also not screw up permissions?

valtteri20:03:27

@dpsutton I had a docker setup about a year ago with figwheel and back then the biggest issue was that mounted directories between the OS (MacOS in this case) and the container were really slow. The situation might have improved since.

thheller20:03:48

@dpsutton if I remember correctly @lilactown did some docker stuff with mounted directories

dpsutton20:03:51

I saw that mentioned in an old log of slack

lilactown20:03:39

It was hell on Windows. Would not recommend

lilactown20:03:26

Using the different file watcher solved most of the problems, but there were also some corporate firewall issues that just ended up making it not worth it

dpsutton20:03:39

don't care about windows 🙂

lilactown20:03:31

For what it's worth, we use docker compose to make it easy to mount source directory is as volumes. There wasn't really anything special that we had to do for Shadow clj s

valtteri20:03:39

I’m using docker on CI when building uberjars and I was suffering the slowness there as well. A workaround in that case was to build the uberjar under /tmp or some other unmounted dir inside the container. I don’t know if this strategy could be leveraged with code hot-reloading tools. I guess there are many many files are they’re changing all the time and all of them need to be visible to the host?

valtteri20:03:20

Here’s my old docker-compose which you can maybe use as a starting point if interested https://gist.github.com/vharmain/9dda15880b1b93ede2ec2045040b0d26

valtteri20:03:09

One gotcha is to have a volume for .m2 so java-deps don’t get downloaded again and again.

dpsutton20:03:35

good point. thanks

valtteri20:03:11

Anyways I came to same conclusion as @lilactown that it was too much of a hassle and started running hot reloading tools on the host.