fullstack clojurescript development with Calva Jack-in

Viewed 44

Please comment how to start backend and frontend with Calva Jack-in.

There is a clojurescript project for a web-application, I started REPL with calva jack-in (deps.edn + shadow-cljs), and tried to evaluate the function start!/stop! in the REPL. Even though there was no error message, I didn't find a corresponding response with "localhost:3000/", it was expected that "Hello, world" should be shown on browser.

To compile of both frontend and backend successfully:

$ npm install && npx shadow-cljs watch frontend backend

Start the server server with node.js successfully

$ node target/main.js

Clojurescript backend code for reference.

(ns mern.backend.core
  (:require ["express" :as express]))

;; currently broken in shadow-cljs
(set! *warn-on-infer* true)

(defonce server (atom nil))

(def port 3000)

(defn start-server []
  (println "Starting server")
  (let [app (express)]
    (.get app "/" (fn [_req res] (.send res "Hello, world")))
    (.listen app port (fn [] (println "Example app listening on port 3000!")))))

(defn start! []
  ;; called by main and after reloading code
  (reset! server (start-server)))

(defn stop! []
  ;; called before reloading code
  (.close @server)
  (reset! server nil))

(defn main []
  ;; executed once, on startup, can do one time setup here
  (start!))
0 Answers
Related