--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 = "

Hello, world!

" 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!