-
Notifications
You must be signed in to change notification settings - Fork 25
/
spec.jl
68 lines (53 loc) · 1.31 KB
/
spec.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using Morsel
app = Morsel.app()
# Route with HTTP verbs
get(app, "/") do req, res
"hello"
end
post(app, "/") do req, res
# ...
end
# Route with URL vars
route(app, GET, "/hello/<id::Int>/<name::%[a-z]{3}[0-9]{2}>") do req, res
req.params[:id] == 99 ? string("Go to hell ", req.params[:name]) : string("Hello ", req.params[:name])
end
route(app, GET, "/") do req, res
# ...
end
route(app, GET | POST, "/") do req, res
# ...
end
route(app, ALL, "/") do req, res
# ...
end
function handleImageUpload(req, res)
"Nice pix."
end
route(app, POST, "/upload", handleImageUpload)
# Route middleware
auth = Morsel.Midware() do req, res
if !get(session(req), :authenticated, false)
return req, redirect(res, "/login")
end
req, res
end
with(app, auth) do app
get(app, "/private") do req, res
# ...
end
end
namespace(app, "/admin", auth) do app
get(app, "/pages/<page_id::Int>") do req, res
page = get_page(req.params[:page_id])
render("viewName.ejl", page)
end
put(app, "/pages/<page_id::Int>") do req, res
update_page(get_page(req.params[:page_id]), req.params)
redirect(res, "/pages/", req.params[:page_id])
end
end
route(app, GET, "/*") do req, res
res.headers["Status"] = 404
render("404.ejl")
end
start(app, 8000)