chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] Starting up spiffy for dynamic content


From: Norman Gray
Subject: [Chicken-users] Starting up spiffy for dynamic content
Date: Tue, 08 Mar 2016 12:02:29 +0000


Greetings.

I'm having difficulty working out how to start spiffy, to serve entirely dynamic content. I feel sure I'm missing something really obvious.

I want to serve entirely dynamic content; that is, no static file content, but with me supplying code which turns a request structure into a response structure.

The spiffy documentation at <http://wiki.call-cc.org/eggref/4/spiffy> describes clearly how to do all of the configuration necessary to configure the server and start it, and mentions in passing that it may be necessary to use accept-loop rather than start-server... and so on.

But it doesn't have what I was looking for, namely a description of a dispatcher of some type, which might hand off to handler functions depending on the structure of the incoming URI, but which would at least let me interpose my own handler. If such a thing exists, I would have expected it to be documented in the section 'Starting the server'.

Looking at spiffy.scm, where I'd expect to see this handler is inside handle-incoming-request, around where the compiled-vhost-map is consulted, or _possibly_ inside process-entry, though the latter appears to be very much a filesystem-walker.

If the content of handle-incoming-request included

(handle-exceptions exn
    (begin ...)
  (if (dispatcher)
      ((dispatcher) (current-request))
      (let ((host (uri-host (request-uri (current-request)))))
        ....

then the parameter (dispatcher) could naturally take control at this point.

It occurred to me that I could/should use the vhost-map to do this dispatching, using something like

(vhost-map `((".*" . ,(lambda (continue) ... and ignore (continue)))))

But (a) that would clearly be a hack, and (b) it appears that that's designed to be able to re-parameterise a request, rather than handle it itself, so (c) that would clearly be a hack.

Another possibility is to specify the handle-not-found handler, and make sure to start the spiffy server in a context which has no files at all, so that the handle-not-found handler will always be called. But that also feels like a bit of a hack.

The final possibility is to use intarweb directly, but that's unappealing, since it would require me cut-and-pasting quite a lot of the content of spiffy.scm.

Where this is coming from: I'm pretty familiar with the Racket servlet framework which requires, in serve/servlet <http://docs.racket-lang.org/web-server/run.html>, a request->response mapping function.

If I'm missing something really obvious, then apologies, and could someone hand me the clue-stick?

Best wishes,

Norman


--
Norman Gray  :  https://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK



reply via email to

[Prev in Thread] Current Thread [Next in Thread]