Fork me on GitHub
#cider
<
2021-05-13
>
macrobartfast01:05:34

I’ve created a project with create-cljs-app, which is awesome. However, now I’ve enabled the server option in shadow-cljs.edn, which allows me to add routes, and I want to send data from the front-end to the back. To send a map, I would have to turn it into a string or JSON, right? Two questions (I think): what format is best to send and receive it in? And, assuming I’m right in that I have to wrap the Ring or Compojure routes, how and where do I do this in an app created with create-cljs-app? I don’t have a familiar instance to wrap, as create-cljs-app is a little different than what I set up myself. In my shadow-cljs-edn I have:

:dev-http {8080 {:root "public"
                  :handler app.handler/handler}}
and my handler ns requires are:
(ns app.handler
  (:require [crux.api :as crux]
            [compojure.core :refer :all]
            [compojure.route :as route]
            [muuntaja.middleware :as mw]
            ;; [ring.middleware.json :as json]
            [ :as io]))
and my handler is
(defroutes handler
  (GET "/about" [] "<h1>Hello World</h1>")
  ;; (POST "/test" req (prn (read (:body req))))
  (POST "/test" req (:body req))
  (route/not-found "<h1>Page not found</h1>"))
which returns the request at /test. I need to be able to send a map from the front end and send it off to Crux.

macrobartfast01:05:23

I’m open to total changes in approach… whatever I have here is just from my thrashing along.

dpsutton01:05:06

did you mean to put this in #cider?

macrobartfast01:05:17

the front end is using cljs-http.

macrobartfast01:05:26

so absolutely sorry.

dpsutton01:05:29

no worries at all

macrobartfast01:05:39

what a catastrophe, sorry cider people.

🙂 3
dpsutton01:05:55

not a problem 🙂