【问题标题】:wrap-file through a specific route通过特定路径包装文件
【发布时间】:2017-11-24 03:10:41
【问题描述】:

我正在为我的 compojure 应用程序设置静态资源。我需要使用wrap-file 而不是wrap-resource,因为我需要从文件系统提供静态文件。

我关注了这个wiki并配置了wrap-file

现在我可以从http://localhost/static-file.css 提供我的静态资产

我想做的是在特定上下文中提供我的静态资产http://localhost/context/static-file.css

【问题讨论】:

    标签: clojure resources compojure


    【解决方案1】:

    对于 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)))
    

    【讨论】:

    • 即使 wrap-resources 应用于 "/" 也能正常工作。救生员!
    猜你喜欢
    • 2013-01-23
    • 1970-01-01
    • 2011-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-13
    • 2013-07-15
    • 2012-06-19
    相关资源
    最近更新 更多