Use relative protocol rather than fixed for basePath - #95
Conversation
|
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
|
@slnode ok to test |
|
@billinghamj Thank you for the pull request. Could you please explain what problem/use case are you trying to solve? I am not sure if a protocol-relative URL is valid according to Swagger specification, have you checked the spec? @shelbys the hardcoded protocol was added to support your use case via #61. Will the implementation proposed here work for you too? |
|
@bajtos - We've long-since been using |
|
@bajtos The problem for us is when doing reverse proxying, via a system we don't have control over, the x-forwarded-proto header is not correctly set. When we browse to the explorer, the URLs are not correctly generated. Relative protocols will work in all cases - based on the current browser context. |
|
@billinghamj I see, it makes sense. I am still reluctant to land this patch as it is, as I am concerned that it may break backwards compatibility. I am proposing the following solution that should allow you to implement what you need, while preserving current behaviour for existing users: var proto = opts.omitProtocolInBaseUrl ? '//' :
(headers['x-forwarded-proto'] || opts.protocol || req.protocol) + '://';
var host = headers['x-forwarded-host'] || headers.host;
doc.basePath = proto + host + initialPath;Usage app.use('/explorer', explorer(app, { omitProtocolInBaseUrl: true }));Thoughts? I'll also need you to add a unit-test to verify the new behaviour, see the existing tests for inspiration: https://github.com/strongloop/loopback-explorer/blob/ccfd9c42b08e30e8ea6564735827940c519db308/test/swagger.test.js#L73-L107 |
|
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
|
@slnode test please |
|
Yes that works for me. |
@billinghamj great! could you then update the pull request please? |
|
Closing in favour of #102. |
|
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
No description provided.