Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

configure authorization to work under proxy

  • Loading branch information...
commit 147d20d460c81647aba36faf18dbbe7beff07f2a 1 parent 4eff9d8
@zaach zaach authored
View
2  bin/router
@@ -35,7 +35,7 @@ app.use(function(req, res, next) {
// redirect requests to the api processes
app.use(function(req, res, next) {
if (/^\/api/.test(req.url)) {
- forward(api_url + req.url.replace(/^\/api/,''),
+ forward(api_url + (req.url === '/api/docs' ? '/docs' : req.url),
req, res,
function(err) {
if (err) {
View
3  etc/config.js
@@ -27,7 +27,8 @@ var config = module.exports = {
}
},
auth: {
- scheme: 'hawk'
+ scheme: 'hawk',
+ hostHeaderName: process.env.HOST_HEADER || 'X-Forwarded-Host'
}
},
build_server: {
View
7 lib/api_loader.js
@@ -2,22 +2,23 @@ var walk = require('walkdir'),
path = require('path');
const API_BASE_PATH = path.join(__dirname, 'api');
+const ROUTE_BASE_PATH = __dirname;
function addRouteFromFile(hapiServer, apiPath) {
// hack off ext
var route = apiPath.substr(0, apiPath.length - 3);
- var route = path.relative(API_BASE_PATH, route);
+ var route = path.relative(ROUTE_BASE_PATH, route);
var impls = require(apiPath);
if (Array.isArray(impls)) {
impls.forEach(function (impl) {
impl.path = '/' + route;
- hapiServer.addRoute(impl);
console.log('route:', impl.method, impl.path);
+ hapiServer.addRoute(impl);
});
} else {
impls.path = '/' + route;
- hapiServer.addRoute(impls);
console.log('route:', impls.method, impls.path);
+ hapiServer.addRoute(impls);
}
}
View
1  lib/db/json.js
@@ -38,6 +38,7 @@ module.exports = {
},
getAuthKey: function(email, cb) {
setTimeout(function() {
+ if (!db[email]) return cb('No account found for ' + email);
cb(null, db[email].pass);
}, 0);
return this;
View
2  lib/http_forward.js
@@ -91,6 +91,8 @@ exports.forward = function(dest, req, res, cb) {
preq.setHeader('Authorization', req.headers['authorization']);
}
+ preq.setHeader('X-Forwarded-Host', req.headers.host);
+
// if the body has already been parsed, we'll write it
if (req.body) {
var data;
View
2  test/api.v1.account.js
@@ -12,7 +12,7 @@ describe('the servers', function() {
should.not.exist(err);
should.exist(r);
servers = r;
- client = new Client('http://' + servers.host + ':' + servers.port);
+ client = new Client('http://' + servers.host + ':' + servers.port + '/api');
done();
});
});
View
2  test/api.v1.context.js
@@ -12,7 +12,7 @@ describe('the servers', function() {
should.not.exist(err);
should.exist(r);
servers = r;
- client = new Client('http://' + servers.host + ':' + servers.port);
+ client = new Client('http://' + servers.host + ':' + servers.port + '/api');
done();
});
});
View
2  test/api.v1.payload.js
@@ -15,7 +15,7 @@ describe('the servers', function() {
should.not.exist(err);
should.exist(r);
servers = r;
- client = new Client('http://' + servers.host + ':' + servers.port);
+ client = new Client('http://' + servers.host + ':' + servers.port + '/api');
done();
});
});
View
2  test/api.v1.payload.timestamp.js
@@ -15,7 +15,7 @@ describe('the servers', function() {
should.not.exist(err);
should.exist(r);
servers = r;
- client = new Client('http://' + servers.host + ':' + servers.port);
+ client = new Client('http://' + servers.host + ':' + servers.port + '/api');
done();
});
});
View
2  test/api.v1.status.js
@@ -15,7 +15,7 @@ describe('the servers', function() {
should.not.exist(err);
should.exist(r);
servers = r;
- client = new Client('http://' + servers.host + ':' + servers.port);
+ client = new Client('http://' + servers.host + ':' + servers.port + '/api');
done();
});
});
View
3  test/lib/runner.js
@@ -12,7 +12,8 @@ module.exports = function(cb) {
s.server = spawn(path.join(__dirname, '..', '..', 'bin', 'api'), [], {
env: {
PORT: 0,
- PATH: process.env.PATH
+ PATH: process.env.PATH,
+ HOST_HEADER: 'Host'
}
});
s.server.stdout.on('data', function (data) {
Please sign in to comment.
Something went wrong with that request. Please try again.