Clojure Stand Root Serving as an Application / Octet Stream

I am trying to host static resources along with services in Pedestal 0.5.1 . I use ::file-pathto point to a directory for placing files. This works fine if I go directly to the file http: // localhost: 8888 / index.html , but if I go to the root of the site http: // localhost: 8888 it serves files as application/octet-stream, rather than text/html. I adapted Hello World Sample and has the same behavior.

SIC / hello_world / server.clj

(ns hello-world.server
  (:require [io.pedestal.http :as http]
            [io.pedestal.http.route :as route])
  (:gen-class))

(def routes
  (route/expand-routes [[]]))

(def service
  {:env                 :prod
   ::http/join? false
   ::http/routes routes
   ::http/file-path "/tmp/www"       
   ::http/type          :jetty
   ::http/allowed-origins {:creds true :allowed-origins (constantly true)}       
   ::http/port          8888})

(defonce runnable-service (http/create-server service))

(defn -main
  "The entry-point for 'lein run'"
  [& args]
  (println "\nCreating your server...")
  (http/start runnable-service))

To begin lein run

$ curl -i localhost:8888
HTTP/1.1 200 OK
Date: Fri, 18 Nov 2016 16:02:56 GMT
Last-Modified: Fri, 18 Nov 2016 15:10:22 GMT
Content-Type: application/octet-stream
Content-Length: 12
Server: Jetty(9.3.8.v20160314)

hello world

$ curl -i localhost:8888/index.html
HTTP/1.1 200 OK
Date: Fri, 18 Nov 2016 16:03:02 GMT
Last-Modified: Fri, 18 Nov 2016 15:10:22 GMT
Content-Type: text/html
Content-Length: 12
Server: Jetty(9.3.8.v20160314)

hello world

Is there a way to fix the "/" route to serve the right type of content?

+4
1

, , io.pedestal.http.ring-middlewares/file-info .

, , .

, :

(ns hello-world.service
  (:require
   [io.pedestal.http :as http]
   [io.pedestal.http.ring-middlewares :as middlewares]
   [io.pedestal.http.route :as route]
   [io.pedestal.http.route.definition :refer [defroutes]]))

(defroutes routes
  [[]])

(def service
  {::http/type :jetty
   ::http/port 8080
   ::http/interceptors [http/log-request
                        http/not-found
                        middlewares/session
                        route/query-params
                        (middlewares/file-info)  ; HERE
                        (middlewares/file "/tmp/www")
                        ;; ... insert other interceptors ...
                        (route/router #(deref #'routes) :map-tree)]})

, . -.

, , , - .

/ , index.html .

io.pedestal.http.ring-middlewares/file io.pedestal.http.ring-middlewares/content-type.

Ring - content-type-response .

file-request java.io.File HTTP.

content-type-response URI Content-Type. URI /, - application/octet-stream.

ring.middleware.file-info ( ) File . . file-info-response.

io.pedestal.http.ring-middlewares/file-info ring.middleware.file-info/file-info-response.

+7

Source: https://habr.com/ru/post/1661216/


All Articles