Add opts.omitProtocolInBaseUrl

This commit is contained in:
Miroslav Bajtoš 2015-06-23 16:36:19 +02:00
parent ccfd9c42b0
commit 5462ce9aac
2 changed files with 16 additions and 1 deletions

View File

@ -176,8 +176,9 @@ function addRoute(app, uri, doc, opts) {
var headers = req.headers;
// NOTE header names (keys) are always all-lowercase
var proto = headers['x-forwarded-proto'] || opts.protocol || req.protocol;
var prefix = opts.omitProtocolInBaseUrl ? '//' : proto + '://';
var host = headers['x-forwarded-host'] || headers.host;
doc.basePath = proto + '://' + host + initialPath;
doc.basePath = prefix + host + initialPath;
}
res.status(200).send(doc);
});

View File

@ -105,6 +105,20 @@ describe('swagger definition', function() {
done();
});
});
it('supports options.omitProtocolInBaseUrl', function(done) {
var app = givenAppWithSwagger({ omitProtocolInBaseUrl: true });
var getReq = getAPIDeclaration(app, 'products');
getReq.end(function(err, res) {
if (err) return done(err);
var basePath = res.body.basePath;
expect(basePath).to.match(/^\/\//);
var parsed = url.parse(res.body.basePath);
expect(parsed.protocol).to.equal(null);
done();
});
});
});
describe('Model definition attributes', function() {