I am currently using GrapheneDB for my Neo4J database which I am pulling information from my Ember application. Neo4J requires Basic HTTP Authentication and since I want a more secure method (instead of explicityly stating the headers in my ajax calls), I am trying to use a http-proxy to connect to the database. So via Ember-CLI, I generated a http-proxy with a path at '/api'. Within the proxy file, I have the following:
~/server/proxies/api.js
var proxyPath = '/api';
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){
var credentials = new Buffer('app-id:app-pw').toString('base64');
// include root path in proxied request
req.url = path.join(proxyPath, req.url);
req.headers.authorization = "Basic " + credentials;
proxy.web(req, res, { target: 'http://app-id.sb02.stations.graphenedb.com:24789/db/data/' });
});
};
So when the above is ran, the headers when printed out on the server seems correct:
{ host: 'localhost:4200',
connection: 'keep-alive',
'cache-control': 'max-age=0',
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36',
'accept-encoding': 'gzip,deflate,sdch',
'accept-language': 'en-US,en;q=0.8',
authorization: 'Basic <correct base64 hash>' }
But when going to the my api URL, I get the following request headers:
GET /api HTTP/1.1
Host: localhost:4200
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
And I get a 404 Not Found. But when I remove the authorization header, I get a 401 Unauthorized prompting me for a username/password. Sometimes on the headers it will show: "Authorization: Basic Og==". Either way it doesn't work.
Does anyone know a solution to this? I tried both the example setHeader code in the node-http-proxy documentation and also searched all over the interwebs for information on ember http-proxy but to no avail. Thanks in advanced!