Cross-Origin Resource Sharing ( CORS) not available in jetty version 8

Saturday, 25 February 2017 · 5 messages
RS
Rob Stapper25 Feb 2017 09:34 #
Hi Christian, I'm trying to build a web based frontend with Angular(2) with Basex as backend. Since Angular uses localhost:3000 and basex uses localhost:8984 I need CORS to be activated in the bachend's jetty-service. If I try to activate this by editing the web.xml file I get the message from the jetty that this service is not available. Obviously version 8 of jetty does not support CORS. According to the documentation Jetty 9 should support CORS. Is replacing jett 8 with version 9 somewere on the agenda? Or can I do this myself? (new area for me) I wouldn't mind testrunning it. TIA, Rob Stapper PS. I see the request the request being handled and send back by the backend (basex) but it misses the necessary header. Debugging my Angular app in the browser say that CORS-header is missing.
CG
Christian Grün25 Feb 2017 09:54 #
Hi Rob,
Quoted text · Rob Stapper · 2 lines
> Is replacing jett 8 with version 9 somewere on the agenda? Or can I do this > myself? (new area for me)
“Not with some serious code updates”, as a Jetty developer confirmed to me [1]. However, I would definitely like to tackle this in a future version of BaseX. However, Jetty 9 can be used without restrictions if you ignore our basexhttp script and deploy BaseX as web servlet [2]. Hope this helps, Christian [1] http://stackoverflow.com/questions/32734920/using-jetty-9-and-jetty-xml-with-basex [2] http://docs.basex.org/wiki/Web_Application
MS
Michael Seiferlein reply to Rob Stapper, 25 Feb 2017, 09:3425 Feb 2017 11:16 #
Hi Rob, in addition to Christian’s mail, one more thought: Great, angular2, haven’t had more than a brief look at it so far :-) I guess you are using that NodeJS-application to serve and generate your AngularJS-files, right? Or are there any other reasons you need NodeJS for? If you only need to serve your static files, you may as well use BaseX to serve static contents and put all (e.g. symlink) Angular related stuff to your webapp/static-folder. The documentation is here: http://docs.basex.org/wiki/Web_Application#Available_Services <http://docs.basex.org/wiki/Web_Application#Available_Services> An example can be found here (https://github.com/BaseXdb/basex/tree/master/basex-api/src/main/webapp <https://github.com/BaseXdb/basex/tree/master/basex-api/src/main/webapp>) , there is a static folder that will be mapped to localhost:8984/restxq/static If by any means you need the NodeJS Server next to RestXQ a possible solution might be proxying the requests from NodeJS to your BaseX instance; so from the Browsers perspective all requests are sent to localhost:3000 :-) I used https://www.npmjs.com/package/express-http-proxy <https://www.npmjs.com/package/express-http-proxy> to redirect all request to http://localhost:3000 <http://localhost:3000/>/restxq -> http://localhost:8989/restxq/ <http://localhost:8989/restxq/> If you can not modify your NodeJS-service you might have a look at https://github.com/gr2m/CORS-Proxy: <https://github.com/gr2m/CORS-Proxy:> it provides out-of-the-box CORS headers for arbitrary URLs Lots of options for these OPTIONS headers ;-) Hope this helps a bit. Best from Konstanz Michael P.S. in production it’s usually beneficial to have only a single web-server face the world
Quoted text · Rob Stapper · 16 lines
> Am 25.02.2017 um 09:34 schrieb Rob Stapper <r.stapper at lijbrandt.nl>: > > Hi Christian, > > I’m trying to build a web based frontend with Angular(2) with Basex as backend. > Since Angular uses localhost:3000 and basex uses localhost:8984 I need CORS to be activated in the bachend’s jetty-service. > If I try to activate this by editing the web.xml file I get the message from the jetty that this service is not available. > Obviously version 8 of jetty does not support CORS. According to the documentation Jetty 9 should support CORS. > > Is replacing jett 8 with version 9 somewere on the agenda? Or can I do this myself? (new area for me) > I wouldn’t mind testrunning it. > > TIA, > Rob Stapper > > PS. I see the request the request being handled and send back by the backend (basex) but it misses the necessary header. Debugging my Angular app in the browser say that CORS-header is missing.
RS
Rob Stapper25 Feb 2017 12:14 #
Hi Michael. Thanx fort he extended reply. As you said: a lot of options. Since this is a new area to me, it is a little overwhelming. Well, didn’t have any plans this weekend. Since I use NodeJS only for serving and generating Angular0files, I’ll start checking that one out. Let you guys know when I’ve succeeded. Thnx, Rob
Quoted text · Michael Seiferle · 31 lines
Van: Michael Seiferle [mailto:ms at basex.org] Verzonden: zaterdag 25 februari 2017 11:17 Aan: Rob Stapper CC: BaseX Onderwerp: Re: [basex-talk] Cross-Origin Resource Sharing ( CORS) not available in jetty version 8 Hi Rob, in addition to Christian’s mail, one more thought: Great, angular2, haven’t had more than a brief look at it so far :-) I guess you are using that NodeJS-application to serve and generate your AngularJS-files, right? Or are there any other reasons you need NodeJS for? If you only need to serve your static files, you may as well use BaseX to serve static contents and put all (e.g. symlink) Angular related stuff to your `webapp/static`-folder. The documentation is here: http://docs.basex.org/wiki/Web_Application#Available_Services An example can be found here (https://github.com/BaseXdb/basex/tree/master/basex-api/src/main/webapp) , there is a static folder that will be mapped to localhost:8984/restxq/static If by any means you need the NodeJS Server next to RestXQ a possible solution might be proxying the requests from NodeJS to your BaseX instance; so from the Browsers perspective all requests are sent to localhost:3000 :-) I used https://www.npmjs.com/package/express-http-proxy to redirect all request to http://localhost:3000/restxq -> http://localhost:8989/restxq/ If you can not modify your NodeJS-service you might have a look at https://github.com/gr2m/CORS-Proxy: it provides out-of-the-box CORS headers for arbitrary URLs Lots of options for these OPTIONS headers ;-) Hope this helps a bit. Best from Konstanz Michael P.S. in production it’s usually beneficial to have only a single web-server face the world Am 25.02.2017 um 09:34 schrieb Rob Stapper <r.stapper at lijbrandt.nl>: Hi Christian, I’m trying to build a web based frontend with Angular(2) with Basex as backend. Since Angular uses localhost:3000 and basex uses localhost:8984 I need CORS to be activated in the bachend’s jetty-service. If I try to activate this by editing the web.xml file I get the message from the jetty that this service is not available. Obviously version 8 of jetty does not support CORS. According to the documentation Jetty 9 should support CORS. Is replacing jett 8 with version 9 somewere on the agenda? Or can I do this myself? (new area for me) I wouldn’t mind testrunning it. TIA, Rob Stapper PS. I see the request the request being handled and send back by the backend (basex) but it misses the necessary header. Debugging my Angular app in the browser say that CORS-header is missing.
AB
Andy Bunce25 Feb 2017 12:37 #
Hi Rob, I have used the restxq custom response feature [1] to create the CORS header. Maybe it would work in your case? <http:response> <http:header name="Access-Control-Allow-Origin" value="*"/> ... For example see [2] (of course Jetty 9 support would be great) /Andy [1] http://docs.basex.org/wiki/RESTXQ#Custom_Response [2] https://github.com/apb2006/graphxq/blob/1080533e6ccf8b00351df26ad80e976dc29ebce2/src/graphxq/graphxq.xqm#L199
Quoted text · Rob Stapper · 151 lines
On 25 February 2017 at 11:14, Rob Stapper <r.stapper at lijbrandt.nl> wrote: > Hi Michael. > > > > Thanx fort he extended reply. As you said: a lot of options. Since this is > a new area to me, it is a little overwhelming. > > Well, didn’t have any plans this weekend. > > > > Since I use NodeJS only for serving and generating Angular0files, I’ll > start checking that one out. > > > > Let you guys know when I’ve succeeded. > > > > Thnx, > > > > Rob > > > > *Van:* Michael Seiferle [mailto:ms at basex.org] > *Verzonden:* zaterdag 25 februari 2017 11:17 > *Aan:* Rob Stapper > *CC:* BaseX > *Onderwerp:* Re: [basex-talk] Cross-Origin Resource Sharing ( CORS) not > available in jetty version 8 > > > > Hi Rob, > > > > in addition to Christian’s mail, one more thought: > > > > Great, angular2, haven’t had more than a brief look at it so far :-) > > > > I guess you are using that NodeJS-application to serve and generate your > AngularJS-files, right? Or are there any other reasons you need NodeJS for? > > > > If you only need to serve your static files, you may as well use BaseX to > serve static contents and put all (e.g. symlink) Angular related stuff to > your `webapp/static`-folder. > > > > The documentation is here: http://docs.basex.org/wiki/Web_Application# > Available_Services > > An example can be found here (https://github.com/BaseXdb/ > basex/tree/master/basex-api/src/main/webapp) , there is a static folder > that will be mapped to localhost:8984/restxq/static > > > > > > If by any means you need the NodeJS Server next to RestXQ a possible > solution might be proxying the requests from NodeJS to your BaseX instance; > so from the Browsers perspective all requests are sent to localhost:3000 :-) > > I used https://www.npmjs.com/package/express-http-proxy to redirect all > request to http://localhost:3000/restxq -> http://localhost:8989/restxq/ > > > > If you can not modify your NodeJS-service you might have a look at > https://github.com/gr2m/CORS-Proxy: it provides out-of-the-box CORS > headers for arbitrary URLs > > > > Lots of options for these OPTIONS headers ;-) > > > > Hope this helps a bit. > > > > Best from Konstanz > > > > Michael > > > > > > P.S. in production it’s usually beneficial to have only a single > web-server face the world > > > > Am 25.02.2017 um 09:34 schrieb Rob Stapper <r.stapper at lijbrandt.nl>: > > > > Hi Christian, > > > > I’m trying to build a web based frontend with Angular(2) with Basex as > backend. > > Since Angular uses localhost:3000 and basex uses localhost:8984 I need > CORS to be activated in the bachend’s jetty-service. > > If I try to activate this by editing the web.xml file I get the message > from the jetty that this service is not available. > > Obviously version 8 of jetty does not support CORS. According to the > documentation Jetty 9 should support CORS. > > > > Is replacing jett 8 with version 9 somewere on the agenda? Or can I do > this myself? (new area for me) > > I wouldn’t mind testrunning it. > > > > TIA, > > Rob Stapper > > > > PS. I see the request the request being handled and send back by the > backend (basex) but it misses the necessary header. Debugging my Angular > app in the browser say that CORS-header is missing. > > >

⚡Generated with XQuery