basex-lsp/webapp/lsp-manager/app.xqm
2025-10-13 23:07:01 +01:00

80 lines
1.6 KiB
Text

(:~
app
:)
module namespace app = 'app/common';
import module namespace cm = "app/cm" at "common.xqm";
(:~
: Redirects to the start page.
: @return redirection
:)
declare %rest:path('/app')
function app:redirect(
) as element(rest:response) {
web:redirect('/app/home')
};
(:~
: Returns a file.
: @param $file file or unknown path
: @return rest binary data
:)
declare %rest:path('/app/static/{$file=.+}')
%output:method('basex')
%perm:allow('public')
function app:file( $file as xs:string)
as item()+ {
let $path:=file:base-dir() || 'static/' || $file
return if(file:exists($path))
then cm:response-file($path)
else (
<rest:response>
<http:response status="404">
<http:header name="Content-Language" value="en"/>
<http:header name="Content-Type" value="text/plain; charset=utf-8"/>
</http:response>
</rest:response>,
"The requested resource is not available."
)
};
(:~ start page. :)
declare %rest:path('/app/home')
function app:home() as item()* {
rest:init(true()),
cm:htmx2("home.htm", map{"version" :"0.0.2"})
};
declare %rest:path('/app/profile')
function app:profile() {
cm:htmx2("profile.htm", map{})
};
declare %rest:path('/app/dev')
function app:dev() {
cm:htmx2("dev/home.htm", map{})
};
declare %rest:path('/app/notifications')
function app:notifications() {
cm:htmx2("notifications.htm", map{})
};
declare %rest:path('/app/components')
function app:components() {
cm:htmx2("components.htm", map{})
};
declare %rest:path('/app/tweets')
function app:tweets() {
cm:htmx2("tweets.htm", map{})
};