Skip to content

Instantly share code, notes, and snippets.

@hbbio
Created October 13, 2012 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hbbio/3886045 to your computer and use it in GitHub Desktop.
Save hbbio/3886045 to your computer and use it in GitHub Desktop.
Server.start(
Server.http,
{ ~dispatch }
)
choices = ["hello world", "goodbye world"]
index = string_of_binary(File.read("index.html"))
function dispatch(Uri.relative url) {
match (url) {
case {path: ["getstring"] ...}:
string = Option.default("", List.random_elt(choices));
Resource.source(string, "text/plain")
default:
Resource.source(index, "text/html")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment