简体   繁体   中英

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

I'm working on a ClojureScript Single-Page app with routing on client-side. I'd like to implement a simple server with would serve my index.html as well as CSS/JS. The idea is to pass all requests apart from /static/* down to client-side and allow my SPA to deal with it.

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. 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. See https://github.com/martinklepsch/tenzing for a template project #nobackend.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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