Search code examples
corsschemechicken-schemespiffy

Adding CORS header files to Spiffy (Scheme/Chicken)


I need to connect a web app to a REST interface made in Scheme/Chicken with Spiffy webserver.

How do you add this header using correct Scheme syntax to the .scm config file (starting Spiffy with CSI -s /www/config.scm)?

The header is Access-Control-Allow-Origin: *


Solution

  • When you take a procedure in vhost-map, you can just wrap it in with-headers, like so:

    (vhost-map `((".*" . ,(lambda (cont)
                            (with-headers '((access-control-allow-origin "*"))
                              cont)))))
    

    This uses the with-headers procedure which simply adds headers to the response returned by the thunk. See the Spiffy docs for more info.