RSS Feed

Lisp Project of the Day


You can support this project by donating at:

Donate using PatreonDonate using Liberapay


Tests 😀
CI 😀

We continue to review Lack's middlewares and this one gives you the ability to route requests to different apps depending on the path.

Here is a quick example. We want to plug a blog and admin into our main app:

POFTHEDAY> (defparameter *main-app*
             (lambda (env)
               (list 200 '(:content-type "text/plain")
                     (list (format nil "~A~%This is main app!"
                                   (getf env :path-info))))))

POFTHEDAY> (defparameter *blog*
             (lambda (env)
               (list 200 '(:content-type "text/plain")
                     (list (format nil "~A~%The Blog."
                                   (getf env :path-info))))))

POFTHEDAY> (defparameter *admin*
             (lambda (env)
               (list 200 '(:content-type "text/plain")
                     (list (format nil "~A~%Administration interface."
                                   (getf env :path-info))))))

POFTHEDAY> (clack:clackup
             (:mount "/blog" *blog*)
             (:mount "/admin" *admin*)
            :port 8044)
Hunchentoot server is started.
Listening on

POFTHEDAY> (dex:get "http://localhost:8044/some/page")
This is main app!"

POFTHEDAY> (dex:get "http://localhost:8044/blog/post-1")
The Blog."

POFTHEDAY> (dex:get "http://localhost:8044/admin/blog/posts?id=1")
Administration interface."

Pay attention to paths, returned as the first line of each response. It is relative to the mount point. This middleware rewrites the path so that an app can be mounted with any prefix.

That is it for today. Tomorrow we'll see how we can serve static with Lack.

Brought to you by 40Ants under Creative Commons License