Friday, August 21, 2009

Managing your Javascripts through SHP (3) - Integrate with Servlets

If you do not want to use SHP but would like to use jsmgr, it provides a servlet adapter that you can use - just do the following in your servlet:

;; your servlet...
(require (planet bzlib/jsmgr/servlet-util))
(define start
(make-start "the-path-to-javascript-here..."))

And the servlet will have the exact same functionality. The following is the that enabled the above:

(require web-server/http/request-structs
(planet bzlib/shp:1:1/request)
(planet bzlib/shp:1:1/proxy)
(planet bzlib/http/client)

(define (request-helper request)
(parameterize (($request request))
($query* "s")))

;; we want to take the request's query object (which are quite available through our definitions...)
;; and then map it to
(define (make-start base)
(lambda (request)
(let ((scripts (request-helper request)))
(make-http-client-response "1.1"
'(("Content-Type" . "text/javascript; charset=utf-8"))
(open-javascript-files/base scripts base))
(lambda (x) x)))))

(make-start (-> path-string? (-> request? response/c)))

No comments:

Post a Comment