-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
controller.xql
39 lines (32 loc) · 1.6 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
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, "\.(json|js|md|png|svg)$", "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, "/deploy")) 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>