diff options
| author | Alexander Pickering <alex@cogarr.net> | 2020-01-01 22:37:37 -0500 |
|---|---|---|
| committer | Alexander Pickering <alex@cogarr.net> | 2020-01-01 22:37:37 -0500 |
| commit | 9fae5d516012e2c0802105e67c79e2587a22b9dc (patch) | |
| tree | 1c782ad2cd08bd1ecc4f0b42bd042778b4f34c2e /hw6/app.moon | |
| download | infsci2620-master.tar.gz infsci2620-master.tar.bz2 infsci2620-master.zip | |
Diffstat (limited to 'hw6/app.moon')
| -rw-r--r-- | hw6/app.moon | 43 |
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! |
