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. Gerrit 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.imsi...@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