答案 0 :(得分:3)
BaseX在引擎盖下使用Jetty。您可以修改web.xml
文件以使Jetty发送CORS标头,但
jetty-servlets
库或jetty-servlets
jar添加到您的$CLASSPATH
(BaseX已经发货jetty-servlet
,这是一个不同的类;并且一定要获取与“{1}}匹配的相应版本”包含在BaseX中。在web.xml
文件中包含以下指令:
<web-app>
<!-- add those before the closing web-app tag: -->
<filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
请注意,Jetty似乎不支持发布通配符标头Access-Control-Allow-Origin: *
:默认情况下已经
<init-param>
<param-name>allowedOrigins</param-name>
<param-value>*</param-value>
</init-param>
(将其放入<filter/>
元素中),Jetty使用它来构造正则表达式,并且如果匹配则始终返回Origin:
请求标头的值,但这也应该对您有用。 / p>
示例请求:
$ curl -v -H "Origin: http://foo.example" http://admin:admin@localhost:8984/rest
* Trying ::1...
* Connected to localhost (::1) port 8984 (#0)
* Server auth using Basic with user 'admin'
> GET /rest HTTP/1.1
> Host: localhost:8984
> Authorization: Basic YWRtaW46YWRtaW4=
> User-Agent: curl/7.50.1
> Accept: */*
> Origin: http://foo.example
>
< HTTP/1.1 200 OK
< Content-Type: application/xml; charset=UTF-8
< Content-Length: 152
< Server: Jetty(8.1.18.v20150929)
<
<rest:databases xmlns:rest="http://basex.org/rest" resources="1">
<rest:database resources="1" size="96234589">test</rest:database>
</rest:databases>
* Connection #0 to host localhost left intact
鉴于这似乎是一个相当合理的请求和事情,你可能会成功opening an issue默认包含库,甚至可能默认启用CORS。(库是现在包含在默认情况下)