Merge pull request #69 from strongloop/feature/honour-x-forwarded-headers
swagger: honour X-Forwarded-Proto header
This commit is contained in:
commit
8c5354cc8c
|
@ -166,9 +166,9 @@ function addRoute(app, uri, doc, opts) {
|
||||||
if (hasBasePath) {
|
if (hasBasePath) {
|
||||||
var headers = req.headers;
|
var headers = req.headers;
|
||||||
// NOTE header names (keys) are always all-lowercase
|
// NOTE header names (keys) are always all-lowercase
|
||||||
|
var proto = headers['x-forwarded-proto'] || opts.protocol || req.protocol;
|
||||||
var host = headers['x-forwarded-host'] || headers.host;
|
var host = headers['x-forwarded-host'] || headers.host;
|
||||||
doc.basePath = (opts.protocol || req.protocol) + '://' +
|
doc.basePath = proto + '://' + host + initialPath;
|
||||||
host + initialPath;
|
|
||||||
}
|
}
|
||||||
res.status(200).send(doc);
|
res.status(200).send(doc);
|
||||||
});
|
});
|
||||||
|
|
|
@ -93,6 +93,18 @@ describe('swagger definition', function() {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('respects X-Forwarded-Proto header (behind a proxy)', function(done) {
|
||||||
|
var app = givenAppWithSwagger();
|
||||||
|
getAPIDeclaration(app, 'products')
|
||||||
|
.set('X-Forwarded-Proto', 'https')
|
||||||
|
.end(function(err, res) {
|
||||||
|
if (err) return done(err);
|
||||||
|
var baseUrl = url.parse(res.body.basePath);
|
||||||
|
expect(baseUrl.protocol).to.equal('https:');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Model definition attributes', function() {
|
describe('Model definition attributes', function() {
|
||||||
|
|
Loading…
Reference in New Issue