-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.opa
57 lines (51 loc) · 1.27 KB
/
main.opa
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
/*
* Twopenny. (C) MLstate - 2011
* @author Adam Koprowski
**/
package mlstate.twopenny
/**
* {1 Server definition, URL dispatching}
**/
twopenny_page((title, content, style))(_req) =
toolbar = Toolbar.html()
page =
<div id=#page>
<div id=#main>
{content}
</>
</>
|> apply_css(style, _)
body = <>{toolbar}{page}</>
Resource.html(title, body)
resources = @static_include_directory("img")
urls : Parser.general_parser(http_request -> resource) =
parser
| "/favicon." .* -> _req ->
@static_resource("./img/favicon.png")
| result={Server.resource_map(resources)} -> _req ->
result
| "/img/user-photo/" user=(.*) -> _req ->
Text.to_string(user)
|> User.mk_ref(_)
|> User.get_user_photo_resource(_)
| "/img/user-bg/" user=(.*) -> _req ->
Text.to_string(user)
|> User.mk_ref(_)
|> User.get_user_wallpaper_resource(_)
| "/user/" user=(.*) ->
Text.to_string(user)
|> User.mk_ref(_)
|> Pages.user_page(_)
|> twopenny_page(_)
| "/label/" label=(.*) ->
Text.to_string(label)
|> Label.mk_ref(_)
|> Pages.label_page(_)
|> twopenny_page(_)
| .* ->
Pages.main_page()
|> twopenny_page(_)
/**
* The Twopenny server
*/
server = Server.make(urls)