Tuesday, August 11, 2009

Now - let's say you want to mix & match your URLs, so some are served with SHP, and others are handled by other servlets and file dispatcher of web-server.

There are multiple ways of achieving this of course - servlets can live in a separate directory, files can live in a separate directory, etc. It completely depends on how you set things up above the SHP handler.

Up to now, SHP handler is designed to work in single servlet setting, so it takes control over the whole dispatching process. In the future we can make it live under a particular prefix, but what we've got works for the single servlet purpose.

Now - how do you serve static files within SHP? We'll utilize and abstract over next-dispatcher so SHP will punt the static file dispatching back to web-server.

(require web-server/dispatchers/dispatch)

(define (punt!) (next-dispatcher))

And what we want then is to have a particular shp page contain the following:

(punt!)

Then web-server will take over the handling of the static file dispatching (assuming that is the next dispatcher in web-server setting).

This comes in handy when you want to define a directory to hold, say, javascripts.

So you have a /scripts/* path in your web-server's htdocs path, and you want those to be served alongside of SHP, all you need is to add a /scripts/index.shp in your shp root path with the following:

;; /scripts/index.shp(punt!)

With the combination of the pathinfo handling and the next-dispatching handling, your static javascripts now live side by side with your shp pages.

In order to make the shp page above work, we'll need to introduce it in the eval namespace as follows: