有没有办法让 BaseX 为 HTML 文档提供服务? [英] Is there a way to make BaseX serve an HTML document?

查看:134
本文介绍了有没有办法让 BaseX 为 HTML 文档提供服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让 BaseX 的 HTTP 服务器为存储在数据库中作为原始资源或文件系统的 HTML 文档提供文本/html 内容类型,以便它可以在浏览器中显示?

Is there a way to make BaseX's HTTP server serve an HTML document stored either in the db as a raw resource or in the file system, with a text/html content type, so it can be displayed in a browser?

该文档是一个向 BaseX 发出 XHR 请求的网页.目前,我通过文件协议将其加载到浏览器上.这需要让 Jetty 使用 CORS 标头进行响应,否则同源策略会阻止 XHR 请求.

The document is a web page that does XHR requests to BaseX. Currently, I load it on the browser through the file protocol. This necessitates making Jetty to respond with CORS headers, or else the same origin policy blocks the XHR requests.

然而,这是一种维护负担.BaseX 的每次更新都需要手动获取添加 CORS 标头的 servlet 过滤器的新版本.

However, this is a maintenance burden. Every update to BaseX requires manually getting a new version of the servlet filter that adds the CORS headers.

我希望 BaseX 本身为 HTML 文档提供服务(并成为源),从而消除跨源请求.

I'd like to have BaseX itself serve the HTML document (and become the origin), thus eliminating the cross origin requests.

有可能吗?

推荐答案

默认的 web.xml(位于 BaseXWeb/WEB-INF 中)已经包含要服务的配置/static/ URI 下 ./static 目录中的静态文件:

The default web.xml (located in BaseXWeb/WEB-INF) already includes configuration to serve static files from the ./static directory under the /static/ URI:

  <!-- Mapping for static resources (may be restricted to a sub path) -->
  <servlet>
    <servlet-name>default</servlet-name>
    <init-param>
      <param-name>useFileMappedBuffer</param-name>
      <param-value>false</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/static/*</url-pattern>
  </servlet-mapping>

你也可以看看BaseX DBA,它还充当 BaseX 托管的 Web 应用程序的示例实现,并为某些 JavaScript 文件使用 ./static 文件夹.

You can also have a look at the BaseX DBA, which also acts as an example implementation of web applications hosted by BaseX and makes use of the ./static folder for some JavaScript files.

当然,如果您需要从另一个目录托管的文件,您也可以更改默认的 web.xml.另一种选择总是将文档作为RAW文件存储在数据库中,并提供他们自己有足够的内容类型.由于通过 ./static 文件夹托管文件会绕过 RestXQ 执行并让 Jetty 直接提供文件,与从 BaseX 数据库读取文件相比,您可能会获得一些性能改进.第三种解决方案可能是在 BaseX 前托管一个反向代理来提供静态文件(无论如何通常都会为生产而这样做),但这会增加开发中的一些管理开销.

Of course, you could also change the default web.xml if you require the files hosted from another directory. An alternative would always be to store the documents in a database as RAW files, and serve them with adequate content type on your own. As hosting files through the ./static folder bypasses RestXQ execution and has Jetty offer the files directly, you might have some performance improvements over reading files from BaseX databases, though. A third solution might be to host a reverse proxy in front of BaseX to serve the static files (which is usually be done for production anyway), but this adds some administrative overhead in development.

这篇关于有没有办法让 BaseX 为 HTML 文档提供服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆