basex

Location of CSS files for web applications


I'm new to BaseX and attempting to set up a simple web application. Looking at DBA as an example, I can see that there is a file webapp/dba/static/style.css which is referenced in HTML as <link rel='stylesheet' type='text/css' href='static/style.css'/> with the HTML output in an XQuery module located at webapp/dba/lib/html.xqm. In my own project, I'd like to have an XQuery module in a path such as webapp/first/second/third/default.xqm with a RESTXQ function that returns an HTML document containing link, but I'm unable to determine what path to use for @href.

Looking at the GET request headers, I can see that the browser is looking for /first/second/third/static/style.css. But when I put the CSS file in that path, the browser returns 404 for the CSS file. I've tried several different combinations of location for the CSS file and the path in @href. It seems I am misunderstanding how paths are resolved.


Solution

  • When using RESTXQ there needs to be a function in your app with a path annotation that matches with the browser request path. This function can create any response. It may return file content from anywhere, as your code choses.

    In the case of the DBA app. This function matches any path starting dba/static/... and returns the content of a file from disk at 'static/' || $file relative to the common.xqm module file path. You would need to write something similar in your app.

    Alternatively, simpler but less flexible, in the default BaseX configuration browser requests paths starting '/static/.. are read from automatically from the paths within the webapp/static folder without writing additional code.