-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcontroller.xql
48 lines (41 loc) · 1.69 KB
/
controller.xql
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
xquery version "3.0";
import module namespace console="http://exist-db.org/xquery/console";
declare variable $exist:path external;
declare variable $exist:resource external;
declare variable $exist:controller external;
declare variable $exist:prefix external;
declare variable $exist:root external;
(: redirect requests for app root ('') to '/' :)
if ($exist:path eq '') then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="{(request:get-header('nginx-request-uri'), request:get-uri())[1]}/"/>
</dispatch>
(: handle request for landing page, e.g., http://history.state.gov/ :)
else if ($exist:path eq "/") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/index.xq"/>
</dispatch>
(: handle request for term HTML :)
else if (matches($exist:path, "^/id/\d+$")) then
let $id := replace($exist:path, "^/id/(\d+)$", "$1")
return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/index.xq">
<add-parameter name="id" value="{$id}"/>
</forward>
</dispatch>
(: handle request for term XML :)
else if (matches($exist:path, "^/id/\d+\.xml$")) then
let $id := replace($exist:path, "^/id/(\d+)\.xml$", "$1")
let $log := console:log($id)
return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/modules/get-xml.xq">
<add-parameter name="id" value="{$id}"/>
</forward>
</dispatch>
(: handle requests for ajax services :)
else
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<ignore/>
</dispatch>