이 작은 프로그램이 설정되어 있습니다. / hello-world 엔드 포인트가 JSON을 반환 할 것으로 예상하지만 HTTP 본문은 비어 있습니다.
왜 아무것도 반환하지 않는지 아십니까?
(ns easycharge.core
(:use ring.util.response)
(:require [compojure.core :refer :all]
[compojure.route :as route]
[easycharge.routes.payments :as payments]
[easycharge.db.conn :as db]
[ring.middleware.defaults :refer :all]
[ring.middleware.json :as middleware]
[ring.middleware.cors :refer [wrap-cors]]
)
(:gen-class))
(defn std-redirect [] (redirect "https://www.hi.com/404/"))
(defroutes app-routes
(GET "/payments/:env/:id" [env id] {:hi "there"})
(GET "/hello-world" [] {:msg "hello-world"})
;; (payments/get-payment env id)
;; serves anything in resources/public
(route/resources "/")
(route/not-found (std-redirect)))
(def app (->
app-routes
(wrap-cors :access-control-allow-origin [#".*"]
:access-control-allow-methods [:get :put :post :delete])
(middleware/wrap-json-body {:keywords? true :bigdecimals? true})
(middleware/wrap-json-response)
(wrap-defaults site-defaults)))
문제는 응답 객체를 (response)
fn에 전달하지 않았다는 것 입니다.
예를 들어 hello-world 경로는 다음과 같아야합니다.
(GET "/hello-world" [] (response {:msg "hello-world"}))
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다