Repository navigation
Expand file tree
/
Copy pathcontroller.xql
More file actions
55 lines (47 loc) · 2.48 KB
/
Copy pathcontroller.xql
File metadata and controls
55 lines (47 loc) · 2.48 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
52
53
54
55
xquery version "3.0";
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;
declare variable $allowOrigin := "*";
if ($exist:path eq '') then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="{request:get-uri()}/"/>
</dispatch>
else if ($exist:path eq "/") then
(: forward root path to index.xql :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="index.html"/>
</dispatch>
else if (matches($exist:path, "^/profiles/[^/]+/.+\.(json|js|css|md|png|svg|ttf|woff2)$", "s")) then
let $name := replace($exist:path, "^/profiles/([^/]+)/.*$", "$1")
let $internal := $exist:root || "/profiles/" || $name
return
if (xmldb:collection-available($internal)) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/{$exist:path}"/>
</dispatch>
else
(: Library packages are not web applications. Read the file from the package repository. :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/modules/profile-resource.xql">
<add-parameter name="path" value="{$exist:path}"/>
</forward>
</dispatch>
else if (matches($exist:path, "\.(json|js|css|md|png|svg|ttf|woff2)$", "s")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/{$exist:path}"/>
</dispatch>
(: all other requests are passed on the Open API router :)
else
let $file := if (matches($exist:path, "^/api/(generator/[^/]+/deploy|actions/[^/]+)")) then 'deploy-api.xql' else 'api.xql'
return <dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/modules/{$file}">
<set-header name="Access-Control-Allow-Origin" value="{$allowOrigin}"/>
{ if ($allowOrigin = "*") then () else <set-header name="Access-Control-Allow-Credentials" value="true"/> }
<set-header name="Access-Control-Allow-Methods" value="GET, POST, DELETE, PUT, PATCH, OPTIONS"/>
<set-header name="Access-Control-Allow-Headers" value="Content-Type, api_key, Authorization"/>
<set-header name="Access-Control-Expose-Headers" value="pb-start, pb-total"/>
</forward>
</dispatch>