- simpler startup
- default and configurable chrome - so you can switch the UI chrome depending on the page
- proxy integration - a built-in http/s proxy so you can use AJAX with ease
- HTTP client abstraction, which include https protocol - this is the basis of proxy
Now to start a new site - you just need to do:
;; startup.ss or startup.scm
(require (planet bzlib/shp/start))
(start-shp-server! <path> #:htdocs <htdocs-path> ...)
The following parameters are available:
path: this is the root directory for your SHP scripts
#:port: the port of the server - default to 8080
#:default: this is the path of the default script for each directory - defaults to "index"
#:not-found: the not-found script for the site (within the SHP root directory) - default to
#fas it is optional
#:required: the required script for the site - default to
/include/required- the site will function if the script does not exist within the SHP directory
#:topfilter: the topfilter script for the site - default to #f. If it is specified it must exist or an error will occur
#:chrome: the chrome script for the site - default to #f. If specified it must exist.
Instead of using topfilter to factor out the common chrome, you can now specify a default chrome (through the startup) and dynamically change chrome within the scripts (NOTE - there is only one chrome for a given request).
To specify the default chrome - do it when you startup the shp server via the
#:chromeparameter. Make sure the chrome script does exist.
To disable chrome within the script, issue the following:
;; inside your shp script
To change chrome to another chrome script, issue the following:
;; inside your shp script
A chrome script takes in one parameter, which is the actual results evaluated of all of the inner scripts (so it differs from the topfilter's parameter, which is a procedure). Remember chrome is evaluated last of all scripts, so please ensure there aren't evaluation order dependencies between chrome and other scripts.
A HTTP proxy is built-in by default in SHP to help you integrate with other web services (your own or a third party's). All you need to do is use the following script:
;; /proxy script
And it'll automatically convert the pathinfo into the target URL, and pass the rest of the data in query string or post to pass it to the URL.
Headers are currently filtered, and only headers with the prefix of "bzl-" are passed through (with the "bzl-" prefix stripped).
This is designed for using with AJAX, where there is issue of the same-origin policy, so you can query web services residing in different domains without issues. It is not a full web browser proxy (yet).
Proxy is built on top of
bzlib/http, which will be described later.
To use JSMGR, add the following to your required script:
(require (planet bzlib/jsmgr/shp))
If you have not previously downloaded JSMGR - the above will do it for you the first time you run the code in SHP script, but since JSMGR is quite large as it includes YUI compressor, it's probably best to do so in DrScheme or mzscheme REPL.
Then you can serve js and css with the following code:
;; either /js or /css script
And you can use helpers to generate the URL for you:
;; in your shp scripts
(script* <js1> <js2> ...) ;; generates a <script> xexpr
(css* <css1> <css2> ...) ;; generates a <link> xexpr
They generate the block by utilizing a known url path (i.e.,
/cssfor css) - if you decide to use a different url you'll have to reset the following in your topfilter script:
;; topfilter script
(parameterize ((js-base-path "/new/js/url")
JSMGR is distributed with YUI compressor, which is licensed by Yahoo! under BSD. I do not believe there are license compatibility issues, but let me know if that is not the case.
You can switch to a different compressor of your choice, as long as you implement a
compress!procedure that has the following signature:
(-> path-string? path-string? any). The first is the path to the actual script (need to exist), and the second is the path for the compressed script (need not exist).
JSMGR also comes with a
servlet-utilmodule that allow you to integrate JSMGR into a regular servlet rather than SHP. This is not a well tested feature, however, so let me know if you run into issues.
;; your servlet
(require (planet bzlib/jsmgr/servlet-util))
HTTP Client Abstraction
SHP proxy depends on
bzlib/http, which will be automatically installed if you install SHP. You can use it as a replacement for the
post-impure-port. Besides working with the
http-postalso work with
(require (planet bzlib/http/client))
(http-get <url> <list-of-headers>)
(http-post <url> <data> <list-of-headers>)
The list of headers is a list of string pairs so the headers are easy to construct. The data for http-post is a list of bytes, so you'll have to manually construct the values for now.
bzlib/httpalso depends on
bzlib/net, which provides additional utilities to deal with network code. This module will currently not be supported so I won't document how it can be used.
That's it for SHP 0.2 - happy SHP'ing.