ring

petr.mensik 2017-11-28T16:47:07.000405Z

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 )