I'm starting to work with ember using ember-cli v0.0.47 and trying to get http-proxy to work.
I am trying to make an ajax request to a remote OGC CSW server. The request is a regular HTTP GET request with some additional parameters, and the expected response is an XML document.
Since I am making a cross-search request, I decided to use a server proxy so as not to deal with the CORS product.
I used ember-cli to create a proxy configuration with:
ember-cli generate http-proxy geoland2 http:
In my controller, I defined a "search" action that jquery.ajax uses to communicate with the server:
export default Ember.Controller.extend({ actions: { search: function() { Ember.$.ajax({ url: 'geoland2/geonetwork/srv/eng/csw', contentType: 'application/xml', crossDomain: true, xhrFields: { withCredentials: true }, dataType: 'xml', data: { service: 'CSW', version: '2.0.2', request: 'GetCapabilities' }, }).then( function(data) { alert(data); Ember.$('.results').html(data); }, function(jqXHR, textStatus, errorThrown) { Ember.$('.results').html(jqXHR.status + ' ' + errorThrown + ' - ' + jqXHR.responseText); } ); } } });
Now that this action is activated, I expect the call
geoland2/geonetwork/srv/eng/csw
will be proxied by ember-cli server and sent to
http://geoland2.meteo.pt/geonetwork/srv/eng/csw?service=CSW&version=2.0.2&request=GetCapabilitites
Is this an assumption about what should happen correctly?
In fact, I see that the request is not proxied at all. The ember app is trying to contact
http:
and it crashes with HTTP 404 error because the specified resource is obviously unavailable.
I edited the auto- server/proxies/geoland2.js file server/proxies/geoland2.js , commenting out the line that joined the proxyPath variable with the rest of the URL:
var proxyPath = '/geoland2'; module.exports = function(app) { // For options, see: // https://github.com/nodejitsu/node-http-proxy var proxy = require('http-proxy').createProxyServer({}); var path = require('path'); app.use(proxyPath, function(req, res, next){ // include root path in proxied request //req.url = path.join(proxyPath, req.url); // I commented this line proxy.web(req, res, {target: 'http://geoland2.meteo.pt:80'}); }); };
This seems correct for my use case, as the endpoint of my connection is at
http://geoland2.meteo.pt/geonetwork/srv/eng/csw
And not
http:
I believe that even if this change may be wrong, I need to return something from the original server.
Do I still have to somehow fix some CORS related issues in order for the proxy to work? Or maybe there are a few more files to edit to properly configure http-proxy?