Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 111 lines (68 sloc) 3.654 kb
e7aa877 Claes Wikstrom documented appmods as an example
authored
1
2 <erl>
3
4
5 box(Str) ->
6 {'div',[{class,"box"}],
f6dbbc9 Claes Wikstrom added possibility to name the module in a .yaws file
authored
7 {pre,[], yaws_api:htmlize(Str)}}.
e7aa877 Claes Wikstrom documented appmods as an example
authored
8
9 tbox(T) ->
10 box(lists:flatten(io_lib:format("~p",[T]))).
11
12
13 ssi(File) ->
14 {'div',[{class,"box"}],
15 {pre,[],
16 {ssi, File,[],[]}}}.
17
18
19 out(A) ->
20ece13 Claes Wikstrom more css hackery
authored
20 [{ssi, "TAB.inc", "%%",[{"appmods", "choosen"}]},
e7aa877 Claes Wikstrom documented appmods as an example
authored
21 {ehtml,
bea8261 Claes Wikstrom added log_wrap_size, configurable wrap size for all logs, fixed a bug in...
authored
22 {'div', [{id, "entry"}],
23
e7aa877 Claes Wikstrom documented appmods as an example
authored
24 [{h1, [], "Appmods (Application modules)"},
25
26 {p, [],
0be3c7e Claes Wikstrom untabified all of yaws
authored
27 ["Appmods are a way to let the application programmer take control over the URL path. Or put in another way, to let the application programmer fake real paths in URLs where in reality an Erlang modules is executing. Possibly an example make this easy to understand. Say we have the folowing url"]},
e7aa877 Claes Wikstrom documented appmods as an example
authored
28
29 box("http://yaws.hyber.org/pathelem/foo/bar/x.pdf"),
30
228a647 Claes Wikstrom git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/ya...
authored
31 {p,[],["With the above url, the webserver would try to deliver the file \"/pathelem/foo/bar/x.pdf\" relative to the docroot. However if we had specified \"pathelem\" as an appmod, the server would stop processing the url after seeing the \"pathelem\" part of the URL. Say we had the following in our yaws.conf configuration file"]},
e7aa877 Claes Wikstrom documented appmods as an example
authored
32
33
34 box("
35 <server tita>
0be3c7e Claes Wikstrom untabified all of yaws
authored
36 port = 8001
37 listen = 0.0.0.0
38 docroot = /home/klacke/yaws/yaws/scripts/../www
39 appmods = <pathelem, myappmod>
e7aa877 Claes Wikstrom documented appmods as an example
authored
40 </server>"),
41
42
43
44
45 {p,[],
0be3c7e Claes Wikstrom untabified all of yaws
authored
46 ["Then the webserver would invoke ",
47 {tt,[], "myappmod:out(A)"},
48 " instead of trying to deliver the actual file. When shipping such an ",
49 {a, [{href, "/pathelem/foo/bar/x.pdf"}], "Url"},
50 " there are 2 fields in the #arg record which are especially interesting. If we have the following code in \"myappmod.erl\":"]},
e7aa877 Claes Wikstrom documented appmods as an example
authored
51
52 ssi("code/myappmod.erl"),
53
54 {p,[],"The #arg field called \"appmoddata\" contains the remainder of the path following the encountered appmod and the field \"appmod_prepath\" contains the part of the URL path leading upto the appmod."},
55
56
57 {p,[],
0be3c7e Claes Wikstrom untabified all of yaws
authored
58 "Thus the following url"},
e7aa877 Claes Wikstrom documented appmods as an example
authored
59 box("http://yaws.hyber.org/zap/pathelem/foo/bar/x.pdf?a=b"),
60 {p,[],
0be3c7e Claes Wikstrom untabified all of yaws
authored
61 "Produces the following output:"},
e7aa877 Claes Wikstrom documented appmods as an example
authored
62 box("
63 A#arg.appmoddata = \"/foo/bar/x.pdf\"
64 A#arg.appmod_prepath = \"/zap/\"
65 A#arg.querydata = \"a=b\""),
66
757eca1 Claes Wikstrom ""
authored
67 {br,[],[]},
e7aa877 Claes Wikstrom documented appmods as an example
authored
68
69 {p, [],
b7656de Claes Wikstrom Added support for excluding dirs from an appmod. This is useful for / ap...
authored
70 "Appmods would typically be used by webapplications that want to provide the illusion of proper paths to the browser. "},
71
72 {p, [], "A special case of an appmod that is particularly interesting is the '/' appmod. This used when we want application code to handle all requests. This is common with web frameworks such as Nitrogen."},
73
74 box("
75 <server tita>
76 port = 8001
77 listen = 0.0.0.0
78 docroot = /home/klacke/yaws/yaws/scripts/../www
79 appmods = </, myappmod>
80 </server>"),
81
82 {p, [], "The above configuration snippet is an example of a slash appmod. One complication with the slash appmod is that usually we have a set of folders containing static data, images and java script, and we want yaws to just deliver those files without intervention from the slash appmod. This can be achieved by excluding a set of directories."},
83
84
85 box("
86 <server tita>
87 port = 8001
88 listen = 0.0.0.0
89 docroot = /home/klacke/yaws/yaws/scripts/../www
90 appmods = </, myappmod exclude_paths icons js top/static>
91 </server>"),
92
93 {p, [], "The above configuration will invoke the 'myappmod' erlang module on everything except any file found in directories, 'icons', 'js' and 'top/static' relative to the docroot"}
e7aa877 Claes Wikstrom documented appmods as an example
authored
94
95
bea8261 Claes Wikstrom added log_wrap_size, configurable wrap size for all logs, fixed a bug in...
authored
96 ]
97 }},
98 {ssi, "END2",[],[]}
99 ].
e7aa877 Claes Wikstrom documented appmods as an example
authored
100
101
102
103 </erl>
104
105
106
107
108
109
110
Something went wrong with that request. Please try again.