kit-clj / kit

Lightweight, modular framework for scalable web development in Clojure
https://kit-clj.github.io/
MIT License
486 stars 44 forks source link

Unable to start server after kit-hato module is added #144

Closed viktornar closed 2 months ago

viktornar commented 3 months ago

What

Unable to start server with (go) after kit-hato module is added.

Steps to reproduce

Create a new project with template: clojure -Tclj-new create :template io.github.kit-clj :name kit/guestbook

Start repl and add kit-hato module:

(kit/sync-modules)
(kit/install-module :kit/hato)

Start server with:

(go)

Getting error:

Execution error (IllegalArgumentException) at integrant.core/try-build-action (core.cljc:305).
No method in multimethod 'init-key' for dispatch value: :http/client

system.edn looks like:

{:system/env
 #profile {:dev :dev
           :test :test
           :prod :prod}

 :server/http
 {:port #long #or [#env PORT 3000]
  :host #or [#env HTTP_HOST "0.0.0.0"]
  :handler #ig/ref :handler/ring}

 :handler/ring
 {:router #ig/ref :router/core
  :api-path "/api"
  :cookie-secret #or [#env COOKIE_SECRET "CEANCCPIXLZCAELI"]
  ;; from ring.middleware.defaults. anti-forgery `false` by default because services may not require it
  :site-defaults-config {:params {:urlencoded true
                                  :multipart true
                                  :nested true
                                  :keywordize true}
                         :cookies true
                         :session {:flash true
                                   :cookie-name "kit.guestbook"
                                   :cookie-attrs {:max-age 86400
                                                  :http-only true
                                                  :same-site :strict}}
                         :security {:anti-forgery false
                                    :xss-protection {:enable? true,
                                                     :mode :block}
                                    :frame-options :sameorigin
                                    :content-type-options :nosniff}
                         :static {:resources "public"}
                         :responses {:not-modified-responses true
                                     :absolute-redirects true
                                     :content-types true
                                     :default-charset "utf-8"}}}

 :reitit.routes/api
 {:base-path "/api"
 :env #ig/ref :system/env
 :http/client #ig/ref :http/client}

 :router/routes
 {:routes #ig/refset :reitit/routes}

 :router/core
 {:routes #ig/ref :router/routes
  :env #ig/ref :system/env}
 :http/client {}}

Module install log (install.log.edn):

#:kit{:hato :success}
yogthos commented 2 months ago

Thanks for the report, there were a couple of problems with the way the module was set up. It didn't add the require for kit.edge.http.hato in the core namespace, meaning that the Integrant multimethod wasn't available at runtime, and it was referncing :http/client instead of :http.client/hato. I updated the module, but you'd have to make the changes manually for an existing project unfortunately.

viktornar commented 2 months ago

@yogthos nice work. Tested and confirming that it works now :) Closing issue.