How to run swagger-ui middleware behind a reverse proxy? #342
Comments
Have you tried |
I have, however that only makes swagger-ui work (accessible), but it won't send the requests to the right URL because it uses Swagger's basePath to do that, which swagger-router also uses to route requests. |
Have you tried a recent release? There was a issue/PR for this that was fixed in 0.9.10. |
I'm on 0.9.11 I'm looking into swagger-router and I'm not sure how this could possibly work right now. Swagger-router uses the swagger document |
I thought #317 would fix #297 which seems to be similar to this but maybe it didn't. I'm not sure how swagger-router is coming into the mix as it is not involved in the serving of swagger-ui. Are you saying API requests aren't matching properly? It seemed like you were saying that the swagger-ui API calls were failing to call the correct endpoint. |
Well, sort of. Assuming I have a reverse proxy from Let's say my swagger document looks like this (yaml): basePath: /myBasePath
paths:
/hello:
x-swagger-router-controller: myCtrl
get:
operationId: helloWorld and myCtrl.helloWorld = function (req, res, next) {
res.end('world');
} With this set-up, swagger-router will only route |
In your case, I'd expect the |
If I do that, swagger-router is happy, but not swagger-ui. If my basepath is My current workaround (and it might be the best solution) is to have my reverse proxy point to Thanks for looking into this! |
I think you should make Swagger happy and if there is a bug in the swagger-ui middleware, we fix it. I think a |
I am facing the same dilemma as @Nepoxx |
I've modified swagger-ui to support a specific basepath told the swagger-ui middleware to use my custom made swagger ui. |
I did not want to change swagger-ui client, since it is a node module.
Another base on the first which swagger-ui will consume, with a different basePath.
Note: do not use the swaggerUi middleware that initializeMiddleware provides,
|
Altering I'll see if I can get some documentation published on taking this approach. |
Ok So i faced same issue and would like to know what should I do (im using AspNEtCore with Swagger middleware) with reverse proxy in production |
Hey Guys im facing the same issue. Any solution to this. Anything will be greatly appreciated. Thanks. |
@Nepoxx Hey did you find the solution to the swagger on reverse proxy issue. Will be glad if you could help me out. thanks |
Hey Guys, |
@fredtma comment above is the fix to this issue. It worked for me after attempting the other suggestions. This is the solution if you're using angular and |
None of the answers worked for me. I've solved it using a custom middleware. middlewares/forwardedPrefixSwagger.js
app.js
Note: For this to work the URL must include a trailing slash. |
The way my app is set-up, I have Nginx serving a reverse proxy pointing to my app container in a docker.
I have
http://services.mydomain.com/myservice
point to themyservice
docker. A GET request athttp://services.mydomain.com/myservice/hello
will look likeGET /hello
to my service, notGET /myservice/hello
, so my basePath should be/
.If I set my basePath to that in my swagger document, however, swaggerUI will not send the requests correctly, even if I set the options to
apiDocsPrefix: '/myservice', swaggerUiPrefix: '/myservice'
. It will be able to correctly fetch theapi-docs
, but will make requests tohttp://services.mydomain.com/
and nothttp://services.mydomain.com/myservice/
.If I set my basePath to
/myservice
, swaggerUi will correctly make the requests, but swagger-router will not serve them (because it doesn't know about the reverse proxy).Is there a way to make this set-up work?
The text was updated successfully, but these errors were encountered: