summaryrefslogtreecommitdiff
path: root/hw6/app.moon
diff options
context:
space:
mode:
Diffstat (limited to 'hw6/app.moon')
-rw-r--r--hw6/app.moon43
1 files changed, 43 insertions, 0 deletions
diff --git a/hw6/app.moon b/hw6/app.moon
new file mode 100644
index 0000000..98b15b7
--- /dev/null
+++ b/hw6/app.moon
@@ -0,0 +1,43 @@
+--Alexander Pickering (amp215@pitt.edu)
+--
+-- More moonscript!
+-- $ luarocks install xavante
+-- $ moon app.lua
+
+web = require("xavante")
+hw5 = require("hw5")
+
+pages = {}
+add_page = (pat, fun) -> table.insert(pages, {match: pat, with: fun})
+
+hello = (req, res, indexname) ->
+ res.content = "<html><h1>Hello, world!</h1></html>"
+ res
+
+add_page("^/$",hello)
+
+decode_entity = (s) ->
+ --decode the number using base 16, then convert the number to a string
+ string.char(tonumber(s,16))
+
+proper = (req, res, indexname) ->
+ query = req.parsed_url.query
+ --Decode the %20 entties in the string
+ decoded = string.gsub(query,"%%(%d+)",decode_entity)
+ mixed = hw5(decoded)
+ --Poor man's json
+ quoted = [string.format("%q",word) for word in *mixed]
+ res.content = "[" .. table.concat(quoted,",") .. "]"
+ res
+
+add_page("^/proper$",proper)
+
+config = {}
+config.server =
+ host: "*"
+ port: 8080
+
+config.defaultHost = {rules: pages}
+
+web.HTTP(config)
+web.start!