Skip to content

Instantly share code, notes, and snippets.

@dckc
Created July 28, 2015 23:16
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 dckc/235c8593073ce2ec938d to your computer and use it in GitHub Desktop.
Save dckc/235c8593073ce2ec938d to your computer and use it in GitHub Desktop.
monte web server example
def [=> UTF8] | _ := import("lib/codec/utf8")
def [=> makeHTTPEndpoint] | _ := import("lib/http/server")
def [=> tag] | _ := import("lib/http/tag")
def simplePage(content):
escape badBody:
def body := UTF8.encode(content, badBody)
def headers := [
"Connection" => "close",
"Content-Length" => `${body.size()}`,
]
return [200, headers, body]
catch _:
return null
def helloWeb(request):
escape badRequest:
def [[verb, path], headers] := request
def body := tag.body(
tag.h1("Hello!"),
tag.p("This is a Monte webserver."),
tag.h2("Request Info"),
tag.p(verb),
tag.p(path),
tag.p(`$headers`))
return simplePage(`$body`)
catch _:
return null
def start(makeSocket):
makeHTTPEndpoint(makeSocket()).listen(helloWeb)
[=> start]
def [=> strToInt] | _ := import("lib/atoi")
def [=> start] | _ := import("../tut/web1")
def makeSocket():
def portArg := currentProcess.getArguments().last()
def via (strToInt) portNum := portArg
return makeTCP4ServerEndpoint(portNum)
start(makeSocket)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment