-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler
executable file
·83 lines (66 loc) · 1.34 KB
/
handler
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
base=`dirname $0`
#
source $base/lib/funcs
# DEBUG
set -x
#PS4='+${FUNCNAME[-1]:- }@${BASH_SOURCE[-1]##*/}:${LINENO}: '
PS4='+${FUNCNAME[0]:- }@${BASH_SOURCE[0]##*/}:${LINENO}: '
#
include_module $base/modules/http
include_module $base/modules/route
#
handle_traps EXIT
#
# call_module_func http __init
array_echo()
{
echo -e "key=$2 value=$1<br>"
}
function array_echon()
{
echo "key=$2 value=$1"
}
default_handler()
{
html_raw "
<div class=\"wrapper\">
<div>Url=$REQUEST_URI and router=$route</div>
</div>
"
#echo -e "<html><pre>"
#echo "Url = $url, filename=$filename"
html_raw "
<pre>
$(foreach _HEADER array_echo)
</pre>
"
}
parse_request &>/dev/null
#parse_request
#
include_module $base/modules/html
#
html_start
route=${URI_PARTS[0]}
route=${route#/}
# check route is present in ./routes/
ls -1 $base/routes|grep $route &>/dev/null
if [ $? -gt 0 ]; then
error_notfound
title "404 Not Found"
html_raw "Path /$route not found"
#echo -e "<html><head><title>404 Not Found</title></head><body>Path /$module not found</body></html>"
exit 0
fi
http_ok
http_content_type
end_headers
include_module routes/$route
router_handle $route || default_handler
filename="$base$url"
#html div ([class]="wrapper")
#html c pre
#html c pre "Url = $url, filename=$filename"
# ( set -o posix ; set )
call_module_func $route __shutdown