Skip to content

Instantly share code, notes, and snippets.

@ox
Created March 4, 2012 08:14
Show Gist options
  • Save ox/1971235 to your computer and use it in GitHub Desktop.
Save ox/1971235 to your computer and use it in GitHub Desktop.
Flea web server using Rack and my own flea fork
require 'rack'
require 'flea'
interpreter = Flea::Interpreter.new
run Proc.new { |env|
interpreter.run(File.read(File.new("server.scm")))
a = interpreter.evaluate([:call, env]).map! {|x|
interpreter.evaluate(x)
}
a = [a[0], a[1], a[2..-1]]
}
(define routes (hash-new))
(define get
(lambda (path proc)
(hash-set routes path proc)))
(define router
(lambda (env)
(if (nil? (hash-get routes (hash-get env "REQUEST_PATH")))
((hash-get routes "/") env)
((hash-get routes (hash-get env "REQUEST_PATH")) env))))
(define call
(lambda (env)
(router env)))
(load "router.scm")
(define headers (hash-new))
(hash-set headers "Content-Type" "text/html")
(get "/"
(lambda ()
(append (list 200 headers) (file-read (file-new "server.scm" "r")))))
(get "/something"
(lambda (env)
(append (list 200 headers) "something")))
(get "/special"
(lambda (env)
(append (list 200 headers) "SPECIAL")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment