nbb

Gregory Bleiker 2025-04-24T09:55:22.220149Z

I'm trying some deno stuff. Any chance to get something like this to run?

(ns server)

(def port 8080)

(defn handler [req]
  (let [agent (-> req (.-headers) (.get "user-agent"))
        body (str "Your user agent is: " (or agent
                                             "Unknown"))]
    (new js/Response body #js {:status 200})))

(-> Deno
    .serve handler #js {:port port})
I'm invoking with
deno run -A npm:nbb server.cljs
Currently, it is not finding the global Deno object, but there might be a lot of other issues.

borkdude 2025-04-24T09:55:55.724119Z

The global Deno object can be found with js/Deno

borkdude 2025-04-24T10:04:56.164969Z

This script works with your invocation:

(ns server)

(def port 8080)

(defn handler [req]
  (let [agent (-> req (.-headers) (.get "user-agent"))
        body (str "Your user agent is: " (or agent
                                             "Unknown"))]
    (new js/Response body #js {:status 200})))

(js/Deno.serve handler #js {:port port})

borkdude 2025-04-24T10:05:45.273679Z

The threading macro invocation should have been:

(-> js/Deno (.serve handler #js {:port port}))

Gregory Bleiker 2025-04-24T11:02:45.385889Z

@borkdude thanks A LOT! I can't believe this isn't hyped more, I find this to be frickin' awesome. I have a datastar sample I'm going to incorporate. If it works it would be like 20 lines of code and nearly 0 setup. I'm excited!

❤️ 2
2025-04-24T13:20:52.268999Z

Had written a cljs project that uses deftype implementing the ILookup protocol from cljs.core. When importing it into nbb, it throws the following error:

ILookup does not exist
Am I just importing ILookup from the wrong source or are protocols just not supported in nbb currently?

borkdude 2025-04-24T13:43:48.350349Z

built-in CLJS protocol implementations on deftypes are currently not supported in SCI

2025-04-24T14:02:35.872709Z

Thanks