This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-28
Channels
- # adventofcode (2)
- # bangalore-clj (3)
- # beginners (171)
- # boot (28)
- # chestnut (3)
- # cljs-dev (20)
- # cljsjs (5)
- # clojure (280)
- # clojure-austin (1)
- # clojure-czech (1)
- # clojure-dev (9)
- # clojure-dusseldorf (2)
- # clojure-greece (20)
- # clojure-italy (6)
- # clojure-poland (16)
- # clojure-russia (7)
- # clojure-serbia (4)
- # clojure-sg (1)
- # clojure-spec (18)
- # clojure-uk (153)
- # clojurescript (57)
- # core-async (9)
- # cursive (21)
- # data-science (29)
- # datomic (18)
- # dirac (8)
- # docker (6)
- # duct (1)
- # emacs (50)
- # fulcro (15)
- # hoplon (56)
- # klipse (3)
- # leiningen (14)
- # lumo (1)
- # off-topic (5)
- # onyx (13)
- # other-languages (14)
- # pedestal (1)
- # perun (5)
- # planck (17)
- # re-frame (10)
- # reagent (2)
- # ring (1)
- # spacemacs (51)
- # sql (14)
- # test-check (16)
- # testing (1)
- # unrepl (93)
I've already asked this in #ring-swagger but since it's related to Ring and Compojure I am gonna try it here as well 🙂 I am trying to serve both static content and JSON responses from API however I am struggling with return of correct content type (currently everything is either plain or octet-stream, even files linked from index.html like CSS or SVG). This is the API configuration
(def app
(api
(assoc api-config
:middleware [[wrap-resource resources-root]
[wrap-cors :access-control-allow-origin [#"\\*"] :access-control-allow-methods [:get :post :put :delete :patch]]
wrap-reload
[wrap-defaults (-> site-defaults
(assoc-in [:not-modified-responses] true)
(assoc-in [:security :anti-forgery] false)
(assoc-in [:security :ssl-redirect] (not (:dev env)))
(assoc-in [:security :hsts] (not (:dev env))))]])
(context "/auth" []
api-routes-login
api-routes-password)
(context "/api" []
:header-params [authorization :- String]
:middleware [[wrap-authentication config/backend]]
api-routes-calendar ; more routes here
(undocumented (route/resources "/" {:root resources-root})
app-routes
not-found-routes)))
Where app-routes are
(defn- get-page
"Servers HTML page from server"
([]
(get-page "index.html"))
([page]
(content-type (resource-response page {:root resources-root}) "text/html")))
(defroutes app-routes
(GET "/" [] (get-page))) ;etc
Basically the same configration worked with plan Compojure (now I am using compojure-api) so what am I doing wrong here? I also tried wrap-content
middleware (which can't really work according to https://stackoverflow.com/questions/29337676/why-does-rings-resource-response-respond-with-application-octet-stream-content )