-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathyown.io
More file actions
51 lines (43 loc) · 1.02 KB
/
yown.io
File metadata and controls
51 lines (43 loc) · 1.02 KB
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
//
// Yown
// a little web doodad for Io
//
doRelativeFile("yown/splitlines.io")
Yown := Object clone do(
list("builder", "splitlines", "webrequest", "webserver") foreach(lib,
doRelativeFile("yown/" .. lib .. ".io"))
//
// The `get`, `put`, etc.
// (Incoming action handlers)
//
handlers := Map clone
list("get", "post", "put", "delete") foreach(action,
handlers atPut(action, List clone)
setSlot(action,
method(url, addHandler(call message name, url, call message argAt(1)))
)
)
addHandler := method(action, url, block,
handlers at(action) append(list("^#{url}$" interpolate asRegex, block))
)
handleRequest := method(req,
match := handlers at(req command asLowercase) detect(l,
req queryPath matchesRegex(l at(0))
)
if (match,
doMessage(match at(1)),
"404 NOT FOUND")
)
//
// Starts the builtin server
//
run := method(
WebServer run(self)
)
//
// Main HTML method
//
html := method(
Builder doMessage(call message)
)
)