[racket] Help needed in writing Macro to transform (lambda (req) ....) to be used in web-server/servlet using auth cookies

From: J G Cho (gcho at fundingmatters.com)
Date: Sun Jun 26 14:48:42 EDT 2011

>
> What did you think it would do?

I had in mind that it would start a loop listening on 8080...

>
> The documentation above that example says:
>
> "Constructs an appropriate dispatch-server-config^, invokes the
> dispatch-server@, and calls its serve function."
>
> And serve (found from clicking on the dispatch-server@ link) says:
>
> "Runs the server—the confirmation channel will be send an exception if
> one occurs starting the server or the port number if there is none—and
> returns a procedure that shuts down the server."

They all say that. Now it makes sense but when I read (okay more like
skim) it just went over my head...

>
> The procedure that you get back will shut it down. So, when you ran
> the result, you were turning OFF the server.

I saw it for the first time ever--a stop proc being returned when
starting a server in Racket Systems tutorial. Based on my limited
exposure to 'systems prog', server starts some while loop and ctr-c to
stop. I seem to have lots of mental baggage that's not helping me out
understanding here.

>
> In the case of your command-line version, since there is nothing left
> in the program to do, racket exits and the server shuts off. In
> DrRacket, however, it keeps running because you can still do things in
> the REPL.
>
> If you keep reading the page that that example is on you'll see two
> useful things:
>
> "(do-not-return) → void
>
> This function does not return. If you are writing a script to load the
> Web Server you are likely to want to call this functions at the end of
> your script."

I saw that scrolling up and down the page but it did not register. I
have not seen a procedure that 'does not return'. Right now, I am
going, you can do such thing?

>
> And
>
> "serve/launch/wait"
>
> which is what is underneath serve/servlet to open up a browser and
> leave the server running until you quit.
>
> I recommend using serve/launch/wait.
>
> Jay

I have not tried serve/launch/wait yet (I will soon) but got the file
server to work. It now reads:

#lang racket

(require web-server/web-server
         web-server/dispatchers/filesystem-map)
(require (prefix-in files: web-server/dispatchers/dispatch-files))

(define (start-file-server base)
   (serve
      #:dispatch
      (files:make
         #:url->path (make-url->path base)
         #:path->mime-type (lambda (path) #"text/html; charset=utf-8")
         #:indices (list "index.html"))
      #:port 8080))

(define stop (start-file-server (current-directory)))

I do

curl localhost:8080 and it prints out index.html.

> (stop)

does stop the server and curl cannot connect to host.

Thanks for sorting out my confusion and guiding me thru.

I did some introspection as to why I am so confused. After all, I did
follow system tutorial and web apps tutorial without this much
confusion. I think both contained materials that I had some
familiarity. (tcp http loop servlet digesting req and making
response...)

This configuration of dispatchers section, I feel like I am surrounded
by all new things. Could not make head or tails... or tell which was
up or down.

Thanks again.



Posted on the users mailing list.