2017-06-21 69 views
0

我为我的compojure应用程序设置了静态资源。我需要使用wrap-file而不是wrap-resource,因为我需要从文件系统提供静态文件。通过特定路线包装文件

我跟着这个wiki和配置wrap-file

现在我能够从http:\\localhost\static-file.css

我想要做的就是为我的静态资产在特定的情况下为我的静态资产http:\\localhost\context\static-file.css

回答

2

有了Compojure路由,重要的是要记住,任何路由都可以封装在中间件中,而不仅仅是顶级集合的路由。考虑到这一点,我们可以使用Compojure的context在需要的地方安装文件系统路由。

(defroutes app-routes 
    (GET "/" [] "Hello World") 
    (context "/context" [] 
      (-> (route/not-found "File Not Found") 
       (wrap-file "path-to/static-files"))) 
    (route/not-found "Not Found")) 

(def app 
    (-> app-routes 
     (wrap-defaults site-defaults))) 
+0

太好了。谢谢。这工作 – prasann