【问题标题】:How to run http-kit using boot?如何使用引导运行 http-kit?
【发布时间】:2017-02-25 00:51:53
【问题描述】:

使用引导运行时,我无法从 http-kit 服务器获得任何响应。它适用于码头。当我运行boot run 时,它会在一段时间后退出。所以我添加了(boot (wait)),它不会终止,但服务器似乎没有运行。

; core.clj
(ns server.core
    (:use [compojure.route :only [files not-found]]
          [compojure.handler :only [site]]
          [compojure.core :only [defroutes GET POST DELETE ANY context]]
          org.httpkit.server))

(defn hello [] 
    "Hello from httpkit")

(defroutes api-routes
    (GET "/" [] (hello)))

(defn -main []
    (run-server api-routes {:port 8080}))

boot.clj 文件:

;boot.clj
(set-env!
    :source-paths #{"src"}
    :dependencies '[[org.clojure/clojure "1.8.0"]
                    [ring "1.5.0"]
                    [compojure "1.5.1"]
                    [http-kit "2.2.0"]])

(require '[server.core :as server])

(deftask run []
    (with-pre-wrap fileset (server/-main) fileset)
    (boot (wait)))

【问题讨论】:

    标签: clojure compojure ring http-kit boot-clj


    【解决方案1】:

    您可以使用boot-http 和类似以下内容:

     (boot (serve :handler 'server/-main :reload true) (wait))
    

    【讨论】:

    • 我使用了 boot-http 并像这样运行它:(boot (serve :handler 'server.core/-main :reload true) (wait)))。但是 boot 在 3000 处启动码头,并且在加载 url 时我得到Problem accessing /. Reason: Wrong number of args (1) passed to: core/-main。使用 lein 非常简单直接,不知道为什么 boot 会变得如此困难。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-26
    • 1970-01-01
    • 1970-01-01
    • 2018-05-17
    • 2018-01-19
    • 2017-08-12
    • 2014-03-30
    相关资源
    最近更新 更多