The PLT Web Server isn't a Library

I decided to hack a bit on the Wiki Diamond project tonight. First decision: choose a language. Because of my recent ramblings about flexible syntax and semantics, and because I already have it installed on my home machine, I chose PLT Scheme.

I decided to start by creating a simple hello-world web page, using the PLT web-server framework. If only it were that easy...

If you do a search for "web server" in the PLT help desk, you will find:

The _Web_ _server_ collection provides two launchers. The "web-server" launcher starts the Web server. The "web-server-monitor" launcher monitors a Webserver by periodically sending it requests. Both launchers support the-h or --help flags which describe other available options.

Consternation. This is a program, not an API. I'm a programmer, damnit, not a user. Ah, but if you scroll down some, you will find:

Requiring the library _web-server.ss_, via (require (lib "web-server.ss" "web-server"))
provides the serve function, which starts the server with more configuration options.

That's what I'm talkin' about! Now, said serve function takes a single "configuration" argument. What's a configuration you ask? That's a good question, and one that they don't feel like answering. The only documented way to create a configuration is to load it from a file. I hate file clutter, and besides the file format isn't documented either. So I dig into the sources.

It turns out there's a make-configuration function that you can use. It's actually quite difficult to find the definition of this function, because they use a provide-define-struct macro to create it -- and so the name of the function isn't actually mentioned anywhere in the definition. This wouldn't be a problem if the "jump to definition" feature worked across files and understood macros, but it does neither. You lose.

Anyway, now I have some code:

(require (lib "web-server.ss" "web-server"))
(require (lib "configuration-structures.ss" "web-server"))
(define config
  (make-configuration 
   8080   ; port
   60     ; wait timeout
   60     ; connect timeout
   null   ; virtual hosts
   ))
(define server (serve config))

I ran my server, and it worked, but then I realized that (duh!) it didn't do anything. If you try to retrieve the front page, you get nothing -- not even whitespace. It just disconnects you immediately.

So I figure that maybe I need to make a virtual host. But look at the parameters to the make-host function:

(listof str) (str str -> (U #f str)) (str str sym url str -> str) passwords responders timeouts paths (U oport #f)

Upon sight of this monstrosity, my determination falters. I decide that the PLT web-server was simply not meant to be used as a library, and I've been heading down a dead end.

Tune in tomorrow for the next (not so) exciting episode.

Posted on September 2, 2003 08:00 PM
More programming articles

Comments
Post a comment









Remember info?




Prove you're human. Type "human":