简体   繁体   English

具有客户端路由的SPA的Clojure服务器配置

[英]Clojure server configuration for SPA's with client-side routing

I'm working on a ClojureScript Single-Page app with routing on client-side. 我正在使用ClojureScript单页应用程序,并且在客户端进行路由。 I'd like to implement a simple server with would serve my index.html as well as CSS/JS. 我想实现一个简单的服务器,该服务器将为我的index.html以及CSS / JS提供服务。 The idea is to pass all requests apart from /static/* down to client-side and allow my SPA to deal with it. 这个想法是将/ static / *以外的所有请求传递到客户端,并允许我的SPA处理它。

It turned out to be surprisingly difficult. 事实证明这非常困难。 The snippet below is something I came up, but it doesn't work. 下面的代码片段是我提出的,但是没有用。

(defroutes routes
  (GET "/" []
    (resp/content-type template "text/html"))
  (context "/static" []
    (route/resources "/css" {:root "css"})
    (route/resources "/js" {:root "js"}))
  (route/not-found
    (resp/content-type template "text/html")))

I use boot-http with custom handler. 我使用带有自定义处理程序的boot-http。 Any chance it could cause it? 有可能导致它吗?

Sounds like you don't need a backend at all; 听起来您根本不需要后端; you can develop with boot-http/boot-reload and deploy to gh-pages, firebase, aws or any static file host. 您可以使用boot-http / boot-reload开发并部署到gh-pages,firebase,aws或任何静态文件主机。 See https://github.com/martinklepsch/tenzing for a template project #nobackend. 参见https://github.com/martinklepsch/tenzing以获取模板项目#nobackend。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM