Merge pull request #99 from cndreiter:master

Add `opts.host` to customize host of resource URLs

Close #99
This commit is contained in:
Miroslav Bajtoš 2015-08-04 15:49:01 +02:00
commit d1e02695c8
2 changed files with 12 additions and 1 deletions

View File

@ -193,7 +193,7 @@ function addRoute(app, uri, doc, opts) {
// 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 proto = headers['x-forwarded-proto'] || opts.protocol || req.protocol;
var prefix = opts.omitProtocolInBaseUrl ? '//' : proto + '://'; var prefix = opts.omitProtocolInBaseUrl ? '//' : proto + '://';
var host = headers['x-forwarded-host'] || headers.host; var host = headers['x-forwarded-host'] || opts.host || headers.host;
doc.basePath = prefix + host + initialPath; doc.basePath = prefix + host + initialPath;
} }
res.status(200).send(doc); res.status(200).send(doc);

View File

@ -119,6 +119,17 @@ describe('swagger definition', function() {
done(); done();
}); });
}); });
it('supports opts.header', function(done) {
var app = givenAppWithSwagger({ host: 'example.com:8080' });
getAPIDeclaration(app, 'products')
.end(function(err, res) {
if (err) return done(err);
var baseUrl = url.parse(res.body.basePath);
expect(baseUrl.host).to.equal('example.com:8080');
done();
});
});
}); });
describe('Model definition attributes', function() { describe('Model definition attributes', function() {