2.9 KiB
R7RS Scheme library for Common Gateway Interface
If you dont know what CGI is, in short server runs your Scheme script and displays it's output as a webpage.
Installation
snow-chibi --impls=$SCHEME retropikzel.cgi
Documentation
(handle-request options thunk)
Options must be association list. Thunk must be procedure taking arguments:
- request
- Full request
- headers
- Request headers
- parameters
- Request parameters
- The ?foo=bar&baz=1 part parsed
- Request parameters
- cookies
- Request cookies
- body
- Request body
- files
- Request files
Whatever thunk writes to (current-output-port) is sent back as response.
Environment variables
SCM_CGI_TMPDIR
Path to where uploaded files are stored. Default is /tmp.
Usage examples
These files are shared among all examples. We will be usign Gauche for examples, but you can comment out your preferred implementation or copy just that exec line from scheme-script. (Without the #)
scheme-script:
#!/bin/sh
#exec capy --r7rs --script "$@"
#exec chibi-scheme "$@"
#exec csi -quiet -batch "$@"
#exec icyc -s "$@"
#exec gsi /home/youruser/.gambit_userlib/ "$@"
exec gosh "$@"
#exec kawa --r7rs -Dkawa.import.path=/usr/local/share/kawa/lib/*.sld "$@"
#exec loko --program "$@"
#exec mit-scheme --batch-mode --load "$@"
#exec racket -I r7rs --script "$@"
#exec sash -r7 "$@"
#exec skint "$@"
#exec stklos "$@"
#exec tr7i "$@"
hello.scm:
(import (scheme base)
(scheme write)
(retropikzel cgi))
(handle-request
'()
(lambda (request headers parameters cookies body files)
(display "Content-type: text/html\r\n")
(display "\r\n")
(display "Hello</br>")
(write request)))
Usage lighttpd example
Debian/Ubuntu/Mint:
apt-get install lighttpd
Files in any (same) directory.
lighttpd.conf:
var.basedir = env.PWD
server.document-root = basedir
server.port = 3000
server.modules += ("mod_cgi", "mod_dirlisting")
cgi.assign = (".scm" => basedir + "/scheme-script")
dir-listing.activate = "enable"
run:
chmod +x scheme-cript
lighttpd -D -f lighttpd.conf
Then navigate with your browser to http://127.0.0.1:3000/hello.scm
Usage apache2 example
Debian/Ubuntu/Mint:
apt-get install apache2
a2enmod cgi
systemctl restart apache
Only hello.scm in /var/lib/cgi-bin/
Add shebang line as first line of hello.scm, for example:
#!/usr/local/bin/gosh
run:
chmod +x /var/lib/cgi-bin/hello.scm
Then navigate with your browser to http://127.0.0.1/cgi-bin/hello.scm
If your server does not have cgi-bin directory you can try adding it
mkdir cgi-bin
cgi-bin/.htaccess:
Options +ExecCGI
SetHandler cgi-script
That should work in any other dir too, but you propably want to make it treat only .scm files as cgi scripts.
SetHandler cgi-script "scm"