即使服务器正在提供资产文件,也不会加载它们

时间:2019-05-04 12:33:07

标签: javascript browser server clojure compojure

我已经使用compojure设置了一个最小的Web服务器,如下所示:

(defroutes m-routes
           (GET "/index.html" []
             {:status 200
              :headers {"Content-Type" "text/html"}
              :body (slurp "resources/index.html")})
           (GET "/style.css" []
             {:status 200
              :headers {"Content-Type" "text/css"}
              :body (slurp "resources/style.css")})
           (GET "/index.js" []
             {:status 200
              :headers {"Content-Type" "application/javascript"}
              :body (slurp "resources/index.js")})
           (GET "*" []
             "nothing here"))

index.html

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <div id="map"></div>
    <script async defer
            src="https://maps.googleapis.com/maps/api/js?key=KEY&callback=mapReady">
    </script>
    <div id="toast"></div>
    <script src="index.js" type="text/javascript"></script>
  </body>
</html>

如果尝试从浏览器访问它们,我可以GET的所有资源文件,但是由于某些原因,主页index.html并未加载它们。我可以说,因为没有样式应用于元素。控制台中没有错误。我应该如何使该服务器正常工作?

0 个答案:

没有答案