Last active
June 26, 2016 20:18
-
-
Save wedesoft/b571cc15e81cfcf98e513974085683ff to your computer and use it in GitHub Desktop.
Get session key in Guile Artanis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; prototype Guile repl for the browser | |
(use-modules (srfi srfi-26) (artanis artanis) (artanis cookie) (artanis utils) (ice-9 regex) (ice-9 r5rs)) | |
(init-server) | |
(define (dot lst) (apply cons lst)) | |
(define (quoted expr) (call-with-output-string (cut write expr <>))) | |
(define (line-breaks s) (regexp-substitute/global #f "\n" s 'pre "<br/>" 'post)) | |
(define programs '()) | |
(define env (scheme-report-environment 5)) | |
(define (reset session) | |
(set! programs (assoc-set! programs session '())) | |
(output session (format #f "; session: ~a~&" session))) | |
(define (output session line) | |
(assoc-set! programs session (cons line (assoc-ref programs session)))) | |
(define (repl session line) | |
(catch #t | |
(lambda () | |
(output session line) | |
(let [(result (eval-string line env))] | |
(if (not (unspecified? result)) | |
(output session (format #f "; ~a~&" (quoted result)))))) | |
(lambda (key function fmt vals . args) | |
(let* [(msg (apply format #f fmt vals)) | |
(info (format #f "; ~a" msg))] | |
(output session info))))) | |
(define (editor session) | |
(tpl->response | |
`(html | |
(body | |
,(map (lambda (line) `(p ,(line-breaks (eliminate-evil-HTML-entities line)))) (reverse (assoc-ref programs session))) | |
(form (@ (action "#") (method "post")) | |
(input (@ (type "text") (name "line") (autofocus "autofocus")))))))) | |
(get "/" #:session 'spawn | |
(lambda (rc) | |
(let [(session (:session rc 'spawn))] | |
(reset session) | |
(editor session)))) | |
(post "/" | |
(lambda (rc) | |
(let* [(session (cookie-ref (rc-cookie rc) "sid")) | |
(post-data (map dot (generate-kv-from-post-qstr (rc-body rc)))) | |
(line (uri-decode (assoc-ref post-data "line")))] | |
(repl session line) | |
(editor session)))) | |
(run #:port 80) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sudo docker build -t wedesoft/aiscm | |
# sudo docker run --rm -t -i wedesoft/aiscm /bin/bash | |
# sudo docker run --rm -p 80:80 wedesoft/aiscm | |
FROM debian:jessie | |
MAINTAINER Jan Wedekind <jan@wedesoft.de> | |
ENV ARTANIS_VERSION 0.1.2.1-be890-dirty | |
ENV SERVER_HOME /srv/artanis-repl | |
RUN apt-get update && \ | |
apt-get install -y curl make guile-2.0 guile-2.0-dev | |
RUN mkdir -p /usr/src/artanis && \ | |
curl -SL http://www.wedesoft.de/downloads/artanis-$ARTANIS_VERSION.tar.gz | tar -xzC /usr/src/artanis --strip-components 1 && \ | |
cd /usr/src/artanis && \ | |
./configure && \ | |
make all install | |
RUN mkdir $SERVER_HOME | |
WORKDIR $SERVER_HOME | |
COPY artanis-repl.scm . | |
EXPOSE 80 | |
CMD ["guile", "artanis-repl.scm"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment