I am designing a website using ember and express over node. Its running in a server, say: SERVER_1.
I have few webservices running in another server, say: SERVER_2.
That is:
website in SERVER_1 and webservices available in SERVER_2
SERVER_1 is behind a proxy server. And I am trying to access webservices from SERVER_1:
SERVER_1 =====[PROXY]===> SERVER_2
When I make AJAX webservice calls from SERVER_1, I receive:
NetworkError: 500 Internal Server Error
However, I am able to retrieve values successfully through browser. Only through AJAX code, I am retrieving Network 500 error.
Also for testing, I removed my proxy server setup:
SERVER_1 =====> SERVER_2
and I was able to access all those web services successfully both via AJAX code and browser.
If I have a proxy server in between them:
SERVER_1 =====[PROXY]===> SERVER_2
I am getting -- NetworkError: 500 Internal Server Error
I like to know the procedures to access third-party webservices from a website which is running behind a proxy server?
Additional Info:
Already to fix cross domain web-service access issue (website running in one server and webservices running in some other different servers with different ports), I am using http-proxy npm and my code is as follows:
var express = require('express');
var routes = require('./routes');
var http = require('http');
var path = require('path');
var httpProxy = require('http-proxy');
var endpoint = {
host: 'IP_ADDRESS_WHERE_MY_WEBSERVICES_RUN',
port: 80,
prefix: '/api'
}
var proxy = new httpProxy.RoutingProxy();
var app = express();
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.methodOverride());
app.use(express.cookieParser('xxxxx'));
app.use(express.session());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
app.use(function(req, res) {
if (req.url.indexOf(endpoint.prefix) === 0) {
proxy.proxyRequest(req, res, endpoint);
}
});
app.use(express.bodyParser());
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
app.get('/', routes.index);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
My AJAX call:
$.ajax({
type: 'GET',
async: false,
url: 'API_URL',
success: function (data) {
alert('success');
},
failure: function(error){
alert('error');
}
});
Already I using http-proxy to handle all url's request.
How can I configure my proxy server's IP address and port in the above code, so that I can access all these webservices successfully? Or is there some way to have my proxy configurations in AJAX call?
Can anyone please guide me?
Thank you