RESTXQ oddity?
Monday, 29 January 2024 · 8 messages
MG
Murray, Gregory29 Jan 2024 15:49 #
Hello,
I’m trying to build my first BaseX web application. I’ve got a RESTXQ function for returning static files to the browser, and other RESTXQ functions corresponding to URLs in the web application. The function for static files is based on the one in DBA:
(:~ Returns the specified static file to the browser as binary data. :)
declare
%rest:GET
%rest:path('theocom/static/{$dir=.+}/{$file=.+}')
function c:file($dir as xs:string, $file as xs:string)
{
let $path := file:base-dir() || 'static/' || $dir || '/' || $file
return
(
web:response-header(
map { 'media-type': web:content-type($path) },
map { 'Content-Length': file:size($path) }
),
file:read-binary($path)
)
};Another function returns the home page for the web application. That page works just fine. The HTML document gets returned to the browser, and the static CSS and image files are sent to the browser successfully.
(:~ Returns the home page for the entire web application. :) declare
%rest:GET
%rest:path('theocom')
%output:method('html')
%output:html-version('5')
function c:home()
{
let $params := c:http-params()
return
(
c:extra-response-headers(),
home:get-home-page($params)
)
};
I have another RESTXQ function that corresponds to a URL that goes deeper into the web application:
(:~ Returns a page listing contributors (libraries whose content we've imported), for browsing. :)
declare
%rest:GET
%rest:path('theocom/contributors/{$alpha=[a-z]}')
%output:method('html')
%output:html-version('5')
function c:browse-contributors($alpha as xs:string)
{
let $params :=
map:merge(
(
map:entry("browse", "contributor"),
map:entry("alpha", upper-case($alpha)),
c:http-params()
)
)
return
(
c:extra-response-headers(),
browse:contributors($params)
)
};The problem I’m having is that on this page, the browser returns 404 for the static files, even though the code for the HTML <head> where the CSS files are linked is identical to the home page. Am I doing something wrong, or is the BaseX RESTXQ implementation doing something unexpected?
Thanks,
Greg
Gregory Murray
Director of Digital Initiatives
Wright Library
Princeton Theological Seminary
IL
Imsieke, Gerrit, le-tex29 Jan 2024 17:18 #
Are the two types of pages requesting the CSS by relative path?
For the main page, static/… should be correct, but for theocom/contributors/…, it should probably be ../../static/…
If this is the issue, then you can refer to the static files by absolute path or use
request:path() in order to analyze how many path steps you need to go up for generating relative URLs to the static files.
Just speculating, since I didn’t see your code or the generated HTML in greater detail.
GerritQuoted text · Gregory · 108 lines
On 29.01.2024 15:49, Murray, Gregory wrote: > Hello, > > I’m trying to build my first BaseX web application. I’ve got a RESTXQ function for returning static files to the browser, and other RESTXQ functions corresponding to URLs in the web application. The function for static files is based on the one in DBA: > > (:~ Returns the specified static file to the browser as binary data. :) > > declare > > %rest:GET > > %rest:path('theocom/static/{$dir=.+}/{$file=.+}') > > function c:file($dir as xs:string, $file as xs:string) > > { > > let $path := file:base-dir() || 'static/' || $dir || '/' || $file > > return > > ( > > web:response-header( > > map { 'media-type': web:content-type($path) }, > > map { 'Content-Length': file:size($path) } > > ), > > file:read-binary($path) > > ) > > }; > > Another function returns the home page for the web application. That page works just fine. The HTML document gets returned to the browser, and the static CSS and image files are sent to the browser successfully. > > (:~ Returns the home page for the entire web application. :) > > declare > > %rest:GET > > %rest:path('theocom') > > %output:method('html') > > %output:html-version('5') > > function c:home() > > { > > let $params := c:http-params() > > return > > ( > > c:extra-response-headers(), > > home:get-home-page($params) > > ) > > }; > > I have another RESTXQ function that corresponds to a URL that goes deeper into the web application: > > (:~ Returns a page listing contributors (libraries whose content we've imported), for browsing. :) > declare > %rest:GET > %rest:path('theocom/contributors/{$alpha=[a-z]}') > %output:method('html') > %output:html-version('5') > function /c:browse-contributors/($alpha as xs:string) > { > let $params := > /map:merge/( > ( > /map:entry/("browse", "contributor"), > /map:entry/("alpha", /upper-case/($alpha)), > /c:http-params/() > ) > ) > return > ( > /c:extra-response-headers/(), > /browse:contributors/($params) > ) > }; > > The problem I’m having is that on this page, the browser returns 404 for the static files, even though the code for the HTML <head> where the CSS files are linked is identical to the home page. Am I doing something wrong, or is the BaseX RESTXQ implementation doing something unexpected? > > Thanks, > > Greg > > Gregory Murray > > Director of Digital Initiatives > > Wright Library > > Princeton Theological Seminary >
--
Gerrit Imsieke
Geschäftsführer / Managing Director
le-tex publishing services GmbH
Weissenfelser Str. 84, 04229 Leipzig, Germany
Phone +49 341 355356 110, Fax +49 341 355356 510
gerrit.imsieke at le-tex.de, http://www.le-tex.de
Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930
Geschäftsführer / Managing Directors:
Gerrit Imsieke, Svea Jelonek, Thomas Schmidt
AB
In addition to Gerrit's comments...
This line jumped out as problematic to me.
%rest:path('theocom/static/{$dir=.+}/{$file=.+}')
The pattern =.+ matches the rest of the path. You only need this once at the end of the path.
Maybe just:
%rest:path('theocom/static/{$dir}/{$file=.+}')
/Andy
Quoted text · Gregory · 143 lines
On Mon, 29 Jan 2024 at 14:49, Murray, Gregory <gregory.murray at ptsem.edu> wrote: > Hello, > > > > I’m trying to build my first BaseX web application. I’ve got a RESTXQ > function for returning static files to the browser, and other RESTXQ > functions corresponding to URLs in the web application. The function for > static files is based on the one in DBA: > > > > (:~ Returns the specified static file to the browser as binary data. :) > > declare > > %rest:GET > > %rest:path('theocom/static/{$dir=.+}/{$file=.+}') > > function c:file($dir as xs:string, $file as xs:string) > > { > > let $path := file:base-dir() || 'static/' || $dir || '/' || $file > > return > > ( > > web:response-header( > > map { 'media-type': web:content-type($path) }, > > map { 'Content-Length': file:size($path) } > > ), > > file:read-binary($path) > > ) > > }; > > > > Another function returns the home page for the web application. That page > works just fine. The HTML document gets returned to the browser, and the > static CSS and image files are sent to the browser successfully. > > > > (:~ Returns the home page for the entire web application. :) > > declare > > %rest:GET > > %rest:path('theocom') > > %output:method('html') > > %output:html-version('5') > > function c:home() > > { > > let $params := c:http-params() > > return > > ( > > c:extra-response-headers(), > > home:get-home-page($params) > > ) > > }; > > > > I have another RESTXQ function that corresponds to a URL that goes deeper > into the web application: > > > > (:~ Returns a page listing contributors (libraries whose content we've > imported), for browsing. :) > declare > %rest:GET > %rest:path('theocom/contributors/{$alpha=[a-z]}') > %output:method('html') > %output:html-version('5') > function *c:browse-contributors*($alpha as xs:string) > { > let $params := > *map:merge*( > ( > *map:entry*("browse", "contributor"), > *map:entry*("alpha", *upper-case*($alpha)), > *c:http-params*() > ) > ) > return > ( > *c:extra-response-headers*(), > *browse:contributors*($params) > ) > }; > > > > The problem I’m having is that on this page, the browser returns 404 for > the static files, even though the code for the HTML <head> where the CSS > files are linked is identical to the home page. Am I doing something wrong, > or is the BaseX RESTXQ implementation doing something unexpected? > > > > Thanks, > > Greg > > > > > > Gregory Murray > > Director of Digital Initiatives > > Wright Library > > Princeton Theological Seminary > > > > >
MG
Murray, Gregory29 Jan 2024 19:39 #
Hi Andy,
I didn’t receive a reply from anyone named Gerrit, but I will watch for it. Meanwhile, thank you for your suggestion. I made the change you indicated, but unfortunately I’m still seeing the same behavior.
Thanks,
Greg
Quoted text · Andy Bunce · 78 lines
From: Andy Bunce <bunce.andy at gmail.com> Date: Monday, January 29, 2024 at 11:51 AM To: Murray, Gregory <gregory.murray at ptsem.edu> Cc: basex-talk at mailman.uni-konstanz.de <basex-talk at mailman.uni-konstanz.de> Subject: Re: [basex-talk] RESTXQ oddity? You don't often get email from bunce.andy at gmail.com. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification> In addition to Gerrit's comments... This line jumped out as problematic to me. %rest:path('theocom/static/{$dir=.+}/{$file=.+}') The pattern =.+ matches the rest of the path. You only need this once at the end of the path. Maybe just: %rest:path('theocom/static/{$dir}/{$file=.+}') /Andy On Mon, 29 Jan 2024 at 14:49, Murray, Gregory <gregory.murray at ptsem.edu<mailto:gregory.murray at ptsem.edu>> wrote: Hello, I’m trying to build my first BaseX web application. I’ve got a RESTXQ function for returning static files to the browser, and other RESTXQ functions corresponding to URLs in the web application. The function for static files is based on the one in DBA: (:~ Returns the specified static file to the browser as binary data. :) declare %rest:GET %rest:path('theocom/static/{$dir=.+}/{$file=.+}') function c:file($dir as xs:string, $file as xs:string) { let $path := file:base-dir() || 'static/' || $dir || '/' || $file return ( web:response-header( map { 'media-type': web:content-type($path) }, map { 'Content-Length': file:size($path) } ), file:read-binary($path) ) }; Another function returns the home page for the web application. That page works just fine. The HTML document gets returned to the browser, and the static CSS and image files are sent to the browser successfully. (:~ Returns the home page for the entire web application. :) declare %rest:GET %rest:path('theocom') %output:method('html') %output:html-version('5') function c:home() { let $params := c:http-params() return ( c:extra-response-headers(), home:get-home-page($params) ) }; I have another RESTXQ function that corresponds to a URL that goes deeper into the web application: (:~ Returns a page listing contributors (libraries whose content we've imported), for browsing. :) declare %rest:GET %rest:path('theocom/contributors/{$alpha=[a-z]}') %output:method('html') %output:html-version('5') function c:browse-contributors($alpha as xs:string) { let $params := map:merge( ( map:entry("browse", "contributor"), map:entry("alpha", upper-case($alpha)), c:http-params() ) ) return ( c:extra-response-headers(), browse:contributors($params) ) }; The problem I’m having is that on this page, the browser returns 404 for the static files, even though the code for the HTML <head> where the CSS files are linked is identical to the home page. Am I doing something wrong, or is the BaseX RESTXQ implementation doing something unexpected? Thanks, Greg Gregory Murray Director of Digital Initiatives Wright Library Princeton Theological Seminary
IL
Imsieke, Gerrit, le-tex29 Jan 2024 20:36 #
Hi Murray,
I only replied to the list, not to you personally, on the assumption that you are subscribed to the list.
https://mailman.uni-konstanz.de/pipermail/basex-talk/2024-January/018275.html
Gerrit
Quoted text · Gregory · 144 lines
On 29.01.2024 19:39, Murray, Gregory wrote: > Hi Andy, > > I didn’t receive a reply from anyone named Gerrit, but I will watch for it. Meanwhile, thank you for your suggestion. I made the change you indicated, but unfortunately I’m still seeing the same behavior. > > Thanks, > > Greg > > *From: *Andy Bunce <bunce.andy at gmail.com> > *Date: *Monday, January 29, 2024 at 11:51 AM > *To: *Murray, Gregory <gregory.murray at ptsem.edu> > *Cc: *basex-talk at mailman.uni-konstanz.de <basex-talk at mailman.uni-konstanz.de> > *Subject: *Re: [basex-talk] RESTXQ oddity? > > > > You don't often get email from bunce.andy at gmail.com. Learn why this is important <https://aka.ms/LearnAboutSenderIdentification> > > > > In addition to Gerrit's comments... > > This line jumped out as problematic to me. > > %rest:path('theocom/static/{$dir=.+}/{$file=.+}') > > The pattern =.+ matches the rest of the path. You only need this once at the end of the path. > > Maybe just: > > %rest:path('theocom/static/{$dir}/{$file=.+}') > > /Andy > > On Mon, 29 Jan 2024 at 14:49, Murray, Gregory <gregory.murray at ptsem.edu <mailto:gregory.murray at ptsem.edu>> wrote: > > Hello, > > I’m trying to build my first BaseX web application. I’ve got a RESTXQ function for returning static files to the browser, and other RESTXQ functions corresponding to URLs in the web application. The function for static files is based on the one in DBA: > > (:~ Returns the specified static file to the browser as binary data. :) > > declare > > %rest:GET > > %rest:path('theocom/static/{$dir=.+}/{$file=.+}') > > function c:file($dir as xs:string, $file as xs:string) > > { > > let $path := file:base-dir() || 'static/' || $dir || '/' || $file > > return > > ( > > web:response-header( > > map { 'media-type': web:content-type($path) }, > > map { 'Content-Length': file:size($path) } > > ), > > file:read-binary($path) > > ) > > }; > > Another function returns the home page for the web application. That page works just fine. The HTML document gets returned to the browser, and the static CSS and image files are sent to the browser successfully. > > (:~ Returns the home page for the entire web application. :) > > declare > > %rest:GET > > %rest:path('theocom') > > %output:method('html') > > %output:html-version('5') > > function c:home() > > { > > let $params := c:http-params() > > return > > ( > > c:extra-response-headers(), > > home:get-home-page($params) > > ) > > }; > > I have another RESTXQ function that corresponds to a URL that goes deeper into the web application: > > (:~ Returns a page listing contributors (libraries whose content we've imported), for browsing. :) > declare > %rest:GET > %rest:path('theocom/contributors/{$alpha=[a-z]}') > %output:method('html') > %output:html-version('5') > function /c:browse-contributors/($alpha as xs:string) > { > let $params := > /map:merge/( > ( > /map:entry/("browse", "contributor"), > /map:entry/("alpha", /upper-case/($alpha)), > /c:http-params/() > ) > ) > return > ( > /c:extra-response-headers/(), > /browse:contributors/($params) > ) > }; > > The problem I’m having is that on this page, the browser returns 404 for the static files, even though the code for the HTML <head> where the CSS files are linked is identical to the home page. Am I doing something wrong, or is the BaseX RESTXQ implementation doing something unexpected? > > Thanks, > > Greg > > Gregory Murray > > Director of Digital Initiatives > > Wright Library > > Princeton Theological Seminary >
--
Gerrit Imsieke
Geschäftsführer / Managing Director
le-tex publishing services GmbH
Weissenfelser Str. 84, 04229 Leipzig, Germany
Phone +49 341 355356 110, Fax +49 341 355356 510
gerrit.imsieke at le-tex.de, http://www.le-tex.de
Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930
Geschäftsführer / Managing Directors:
Gerrit Imsieke, Svea Jelonek, Thomas Schmidt
MG
Murray, Gregory29 Jan 2024 21:35 #
Hi Gerrit,
I’m subscribed to the list, but it appears that I have been receiving only some messages posted to the list, not all – probably caused by an overzealous security mechanism on the email server here at my employer. I’ll look into it.
Thanks very much for your suggestion. I see what you mean about relative vs. absolute paths. Yes, I was using absolute paths such as href="static/css/theocom.css" but now I see that using the absolute path such as href="/theocom/static/css/theocom.css" works well and allows me to use the same code for HTML <head> across multiple pages.
Many thanks,
Greg
Quoted text · Imsieke, Gerrit, le-tex · 164 lines
From: Imsieke, Gerrit, le-tex <gerrit.imsieke at le-tex.de> Date: Monday, January 29, 2024 at 2:36 PM To: Murray, Gregory <gregory.murray at ptsem.edu>, basex-talk at mailman.uni-konstanz.de <basex-talk at mailman.uni-konstanz.de> Subject: Re: [basex-talk] RESTXQ oddity? [You don't often get email from gerrit.imsieke at le-tex.de. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ] Hi Murray, I only replied to the list, not to you personally, on the assumption that you are subscribed to the list. https://mailman.uni-konstanz.de/pipermail/basex-talk/2024-January/018275.html Gerrit On 29.01.2024 19:39, Murray, Gregory wrote: > Hi Andy, > > I didn’t receive a reply from anyone named Gerrit, but I will watch for it. Meanwhile, thank you for your suggestion. I made the change you indicated, but unfortunately I’m still seeing the same behavior. > > Thanks, > > Greg > > *From: *Andy Bunce <bunce.andy at gmail.com> > *Date: *Monday, January 29, 2024 at 11:51 AM > *To: *Murray, Gregory <gregory.murray at ptsem.edu> > *Cc: *basex-talk at mailman.uni-konstanz.de <basex-talk at mailman.uni-konstanz.de> > *Subject: *Re: [basex-talk] RESTXQ oddity? > > > > You don't often get email from bunce.andy at gmail.com. Learn why this is important <https://aka.ms/LearnAboutSenderIdentification> > > > > In addition to Gerrit's comments... > > This line jumped out as problematic to me. > > %rest:path('theocom/static/{$dir=.+}/{$file=.+}') > > The pattern =.+ matches the rest of the path. You only need this once at the end of the path. > > Maybe just: > > %rest:path('theocom/static/{$dir}/{$file=.+}') > > /Andy > > On Mon, 29 Jan 2024 at 14:49, Murray, Gregory <gregory.murray at ptsem.edu <mailto:gregory.murray at ptsem.edu>> wrote: > > Hello, > > I’m trying to build my first BaseX web application. I’ve got a RESTXQ function for returning static files to the browser, and other RESTXQ functions corresponding to URLs in the web application. The function for static files is based on the one in DBA: > > (:~ Returns the specified static file to the browser as binary data. :) > > declare > > %rest:GET > > %rest:path('theocom/static/{$dir=.+}/{$file=.+}') > > function c:file($dir as xs:string, $file as xs:string) > > { > > let $path := file:base-dir() || 'static/' || $dir || '/' || $file > > return > > ( > > web:response-header( > > map { 'media-type': web:content-type($path) }, > > map { 'Content-Length': file:size($path) } > > ), > > file:read-binary($path) > > ) > > }; > > Another function returns the home page for the web application. That page works just fine. The HTML document gets returned to the browser, and the static CSS and image files are sent to the browser successfully. > > (:~ Returns the home page for the entire web application. :) > > declare > > %rest:GET > > %rest:path('theocom') > > %output:method('html') > > %output:html-version('5') > > function c:home() > > { > > let $params := c:http-params() > > return > > ( > > c:extra-response-headers(), > > home:get-home-page($params) > > ) > > }; > > I have another RESTXQ function that corresponds to a URL that goes deeper into the web application: > > (:~ Returns a page listing contributors (libraries whose content we've imported), for browsing. :) > declare > %rest:GET > %rest:path('theocom/contributors/{$alpha=[a-z]}') > %output:method('html') > %output:html-version('5') > function /c:browse-contributors/($alpha as xs:string) > { > let $params := > /map:merge/( > ( > /map:entry/("browse", "contributor"), > /map:entry/("alpha", /upper-case/($alpha)), > /c:http-params/() > ) > ) > return > ( > /c:extra-response-headers/(), > /browse:contributors/($params) > ) > }; > > The problem I’m having is that on this page, the browser returns 404 for the static files, even though the code for the HTML <head> where the CSS files are linked is identical to the home page. Am I doing something wrong, or is the BaseX RESTXQ implementation doing something unexpected? > > Thanks, > > Greg > > Gregory Murray > > Director of Digital Initiatives > > Wright Library > > Princeton Theological Seminary > -- Gerrit Imsieke Geschäftsführer / Managing Director le-tex publishing services GmbH Weissenfelser Str. 84, 04229 Leipzig, Germany Phone +49 341 355356 110, Fax +49 341 355356 510 gerrit.imsieke at le-tex.de, https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.le-tex.de%2F&data=05%7C02%7Cgregory.murray%40ptsem.edu%7C6a421401b2d8412ca68608dc2101950f%7C6fb1672fa768436d88c81585060baf28%7C0%7C0%7C638421537900620474%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=QR%2F4IzaqSrAV1QjRJaxwSvVsdbP2s43L5cC4bxzAVsk%3D&reserved=0<http://www.le-tex.de/> Registergericht / Commercial Register: Amtsgericht Leipzig Registernummer / Registration Number: HRB 24930 Geschäftsführer / Managing Directors: Gerrit Imsieke, Svea Jelonek, Thomas Schmidt
MG
Murray, Gregory29 Jan 2024 21:39 #
Correction: I meant to say “Yes, I was using relative paths ….” Apologies.
Quoted text · Murray, Gregory · 173 lines
From: Murray, Gregory <gregory.murray at ptsem.edu> Date: Monday, January 29, 2024 at 3:35 PM To: Imsieke, Gerrit, le-tex <gerrit.imsieke at le-tex.de>, basex-talk at mailman.uni-konstanz.de <basex-talk at mailman.uni-konstanz.de> Subject: Re: [basex-talk] RESTXQ oddity? Hi Gerrit, I’m subscribed to the list, but it appears that I have been receiving only some messages posted to the list, not all – probably caused by an overzealous security mechanism on the email server here at my employer. I’ll look into it. Thanks very much for your suggestion. I see what you mean about relative vs. absolute paths. Yes, I was using absolute paths such as href="static/css/theocom.css" but now I see that using the absolute path such as href="/theocom/static/css/theocom.css" works well and allows me to use the same code for HTML <head> across multiple pages. Many thanks, Greg From: Imsieke, Gerrit, le-tex <gerrit.imsieke at le-tex.de> Date: Monday, January 29, 2024 at 2:36 PM To: Murray, Gregory <gregory.murray at ptsem.edu>, basex-talk at mailman.uni-konstanz.de <basex-talk at mailman.uni-konstanz.de> Subject: Re: [basex-talk] RESTXQ oddity? [You don't often get email from gerrit.imsieke at le-tex.de. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ] Hi Murray, I only replied to the list, not to you personally, on the assumption that you are subscribed to the list. https://mailman.uni-konstanz.de/pipermail/basex-talk/2024-January/018275.html Gerrit On 29.01.2024 19:39, Murray, Gregory wrote: > Hi Andy, > > I didn’t receive a reply from anyone named Gerrit, but I will watch for it. Meanwhile, thank you for your suggestion. I made the change you indicated, but unfortunately I’m still seeing the same behavior. > > Thanks, > > Greg > > *From: *Andy Bunce <bunce.andy at gmail.com> > *Date: *Monday, January 29, 2024 at 11:51 AM > *To: *Murray, Gregory <gregory.murray at ptsem.edu> > *Cc: *basex-talk at mailman.uni-konstanz.de <basex-talk at mailman.uni-konstanz.de> > *Subject: *Re: [basex-talk] RESTXQ oddity? > > > > You don't often get email from bunce.andy at gmail.com. Learn why this is important <https://aka.ms/LearnAboutSenderIdentification> > > > > In addition to Gerrit's comments... > > This line jumped out as problematic to me. > > %rest:path('theocom/static/{$dir=.+}/{$file=.+}') > > The pattern =.+ matches the rest of the path. You only need this once at the end of the path. > > Maybe just: > > %rest:path('theocom/static/{$dir}/{$file=.+}') > > /Andy > > On Mon, 29 Jan 2024 at 14:49, Murray, Gregory <gregory.murray at ptsem.edu <mailto:gregory.murray at ptsem.edu>> wrote: > > Hello, > > I’m trying to build my first BaseX web application. I’ve got a RESTXQ function for returning static files to the browser, and other RESTXQ functions corresponding to URLs in the web application. The function for static files is based on the one in DBA: > > (:~ Returns the specified static file to the browser as binary data. :) > > declare > > %rest:GET > > %rest:path('theocom/static/{$dir=.+}/{$file=.+}') > > function c:file($dir as xs:string, $file as xs:string) > > { > > let $path := file:base-dir() || 'static/' || $dir || '/' || $file > > return > > ( > > web:response-header( > > map { 'media-type': web:content-type($path) }, > > map { 'Content-Length': file:size($path) } > > ), > > file:read-binary($path) > > ) > > }; > > Another function returns the home page for the web application. That page works just fine. The HTML document gets returned to the browser, and the static CSS and image files are sent to the browser successfully. > > (:~ Returns the home page for the entire web application. :) > > declare > > %rest:GET > > %rest:path('theocom') > > %output:method('html') > > %output:html-version('5') > > function c:home() > > { > > let $params := c:http-params() > > return > > ( > > c:extra-response-headers(), > > home:get-home-page($params) > > ) > > }; > > I have another RESTXQ function that corresponds to a URL that goes deeper into the web application: > > (:~ Returns a page listing contributors (libraries whose content we've imported), for browsing. :) > declare > %rest:GET > %rest:path('theocom/contributors/{$alpha=[a-z]}') > %output:method('html') > %output:html-version('5') > function /c:browse-contributors/($alpha as xs:string) > { > let $params := > /map:merge/( > ( > /map:entry/("browse", "contributor"), > /map:entry/("alpha", /upper-case/($alpha)), > /c:http-params/() > ) > ) > return > ( > /c:extra-response-headers/(), > /browse:contributors/($params) > ) > }; > > The problem I’m having is that on this page, the browser returns 404 for the static files, even though the code for the HTML <head> where the CSS files are linked is identical to the home page. Am I doing something wrong, or is the BaseX RESTXQ implementation doing something unexpected? > > Thanks, > > Greg > > Gregory Murray > > Director of Digital Initiatives > > Wright Library > > Princeton Theological Seminary > -- Gerrit Imsieke Geschäftsführer / Managing Director le-tex publishing services GmbH Weissenfelser Str. 84, 04229 Leipzig, Germany Phone +49 341 355356 110, Fax +49 341 355356 510 gerrit.imsieke at le-tex.de, https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.le-tex.de%2F&data=05%7C02%7Cgregory.murray%40ptsem.edu%7C6a421401b2d8412ca68608dc2101950f%7C6fb1672fa768436d88c81585060baf28%7C0%7C0%7C638421537900620474%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=QR%2F4IzaqSrAV1QjRJaxwSvVsdbP2s43L5cC4bxzAVsk%3D&reserved=0<http://www.le-tex.de/> Registergericht / Commercial Register: Amtsgericht Leipzig Registernummer / Registration Number: HRB 24930 Geschäftsführer / Managing Directors: Gerrit Imsieke, Svea Jelonek, Thomas Schmidt
IL
Imsieke, Gerrit, le-tex29 Jan 2024 21:49 #
And sorry for calling you Murray. Only now I realized that it’s your last name. Sorry again, Greg, and I’m glad that it’s working for you now.
Btw, href="static/css/theocom.css" is indeed a relative path. The leading slash makes href="/theocom/static/css/theocom.css" an absolute path.
Gerrit
Quoted text · Gregory · 179 lines
On 29.01.2024 21:39, Murray, Gregory wrote: > Correction: I meant to say “Yes, I was using relative paths ….” Apologies. > > *From: *Murray, Gregory <gregory.murray at ptsem.edu> > *Date: *Monday, January 29, 2024 at 3:35 PM > *To: *Imsieke, Gerrit, le-tex <gerrit.imsieke at le-tex.de>, basex-talk at mailman.uni-konstanz.de <basex-talk at mailman.uni-konstanz.de> > *Subject: *Re: [basex-talk] RESTXQ oddity? > > Hi Gerrit, > > I’m subscribed to the list, but it appears that I have been receiving only some messages posted to the list, not all – probably caused by an overzealous security mechanism on the email server here at my employer. I’ll look into it. > > Thanks very much for your suggestion. I see what you mean about relative vs. absolute paths. Yes, I was using absolute paths such as href="static/css/theocom.css" but now I see that using the absolute path such as href="/theocom/static/css/theocom.css" works well and allows me to use the same code for HTML <head> across multiple pages. > > Many thanks, > > Greg > > *From: *Imsieke, Gerrit, le-tex <gerrit.imsieke at le-tex.de> > *Date: *Monday, January 29, 2024 at 2:36 PM > *To: *Murray, Gregory <gregory.murray at ptsem.edu>, basex-talk at mailman.uni-konstanz.de <basex-talk at mailman.uni-konstanz.de> > *Subject: *Re: [basex-talk] RESTXQ oddity? > > [You don't often get email from gerrit.imsieke at le-tex.de. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification <https://aka.ms/LearnAboutSenderIdentification> ] > > Hi Murray, > > I only replied to the list, not to you personally, on the assumption that you are subscribed to the list. > > https://mailman.uni-konstanz.de/pipermail/basex-talk/2024-January/018275.html <https://mailman.uni-konstanz.de/pipermail/basex-talk/2024-January/018275.html> > > > Gerrit > > On 29.01.2024 19:39, Murray, Gregory wrote: >> Hi Andy, >> >> I didn’t receive a reply from anyone named Gerrit, but I will watch for it. Meanwhile, thank you for your suggestion. I made the change you indicated, but unfortunately I’m still seeing the same behavior. >> >> Thanks, >> >> Greg >> >> *From: *Andy Bunce <bunce.andy at gmail.com> >> *Date: *Monday, January 29, 2024 at 11:51 AM >> *To: *Murray, Gregory <gregory.murray at ptsem.edu> >> *Cc: *basex-talk at mailman.uni-konstanz.de <basex-talk at mailman.uni-konstanz.de> >> *Subject: *Re: [basex-talk] RESTXQ oddity? >> >> >> >> You don't often get email from bunce.andy at gmail.com. Learn why this is important <https://aka.ms/LearnAboutSenderIdentification <https://aka.ms/LearnAboutSenderIdentification>> >> >> >> >> In addition to Gerrit's comments... >> >> This line jumped out as problematic to me. >> >> %rest:path('theocom/static/{$dir=.+}/{$file=.+}') >> >> The pattern =.+ matches the rest of the path. You only need this once at the end of the path. >> >> Maybe just: >> >> %rest:path('theocom/static/{$dir}/{$file=.+}') >> >> /Andy >> >> On Mon, 29 Jan 2024 at 14:49, Murray, Gregory <gregory.murray at ptsem.edu <mailto:gregory.murray at ptsem.edu <mailto:gregory.murray at ptsem.edu>>> wrote: >> >> Hello, >> >> I’m trying to build my first BaseX web application. I’ve got a RESTXQ function for returning static files to the browser, and other RESTXQ functions corresponding to URLs in the web application. The function for static files is based on the one in DBA: >> >> (:~ Returns the specified static file to the browser as binary data. :) >> >> declare >> >> %rest:GET >> >> %rest:path('theocom/static/{$dir=.+}/{$file=.+}') >> >> function c:file($dir as xs:string, $file as xs:string) >> >> { >> >> let $path := file:base-dir() || 'static/' || $dir || '/' || $file >> >> return >> >> ( >> >> web:response-header( >> >> map { 'media-type': web:content-type($path) }, >> >> map { 'Content-Length': file:size($path) } >> >> ), >> >> file:read-binary($path) >> >> ) >> >> }; >> >> Another function returns the home page for the web application. That page works just fine. The HTML document gets returned to the browser, and the static CSS and image files are sent to the browser successfully. >> >> (:~ Returns the home page for the entire web application. :) >> >> declare >> >> %rest:GET >> >> %rest:path('theocom') >> >> %output:method('html') >> >> %output:html-version('5') >> >> function c:home() >> >> { >> >> let $params := c:http-params() >> >> return >> >> ( >> >> c:extra-response-headers(), >> >> home:get-home-page($params) >> >> ) >> >> }; >> >> I have another RESTXQ function that corresponds to a URL that goes deeper into the web application: >> >> (:~ Returns a page listing contributors (libraries whose content we've imported), for browsing. :) >> declare >> %rest:GET >> %rest:path('theocom/contributors/{$alpha=[a-z]}') >> %output:method('html') >> %output:html-version('5') >> function /c:browse-contributors/($alpha as xs:string) >> { >> let $params := >> /map:merge/( >> ( >> /map:entry/("browse", "contributor"), >> /map:entry/("alpha", /upper-case/($alpha)), >> /c:http-params/() >> ) >> ) >> return >> ( >> /c:extra-response-headers/(), >> /browse:contributors/($params) >> ) >> }; >> >> The problem I’m having is that on this page, the browser returns 404 for the static files, even though the code for the HTML <head> where the CSS files are linked is identical to the home page. Am I doing something wrong, or is the BaseX RESTXQ implementation doing something unexpected? >> >> Thanks, >> >> Greg >> >> Gregory Murray >> >> Director of Digital Initiatives >> >> Wright Library >> >> Princeton Theological Seminary >> >
Written for BaseX 10.7. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery