Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't specify host to work correctly with nginx generated subroutes #176

Closed
2 tasks done
Danko14 opened this issue Sep 24, 2024 · 7 comments · Fixed by #178
Closed
2 tasks done

Can't specify host to work correctly with nginx generated subroutes #176

Danko14 opened this issue Sep 24, 2024 · 7 comments · Fixed by #178
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@Danko14
Copy link

Danko14 commented Sep 24, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the regression has not already been reported

Last working version

7.4.0

Stopped working in version

9.0.0

Node.js version

22.9.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

14.0

💥 Regression Report

I'm using fastify with docker and nginx API gateway, so I always need to specify service api url in my swagger configuration, so that it is routed correctly.
after update, I couldn't find "host" parameter I used before, and while it all works fine locally, it crashes on server, being unable to fetch lib files, such as swagger-ui-bundle.js.
e.g. request goes to https://mydomain/docs/swagger-ui-bundle.js while the correct path is https://mydomain/v1/mock-server/docs/swagger-ui-bundle.js and getting either html or 404 response

routePrefix and servers parameters couldn't help me here

maybe I'm missing an obvious solution, but I couldn't find any in documentation or existing tickets.

sources mismatch:
photo_2024-09-24 13 49 58

thanks in advance!

Steps to Reproduce

clone repo
https://github.com/Danko14/fastify-swagger

follow readme steps (create .env & run docker-compose)
you'll get nginx running on 80 and mock server running on 8080 and available on http://localhost/mock-server/
query http://localhost/mock-server/ping to get { msg: 'ok' }
query http://localhost:8080/docs to see swagger docs
query http://localhost/mock-server/docs to see where the problem is

swagger config:
fastify.register( fastifySwagger, { openapi: { info: { title: 'Mock server', description: 'API documentation', version, }, servers: [ { url:https://${process.env.SERVER_API_URL}, description: 'HTTPS' }, { url: http://${process.env.HTTP_HOST}:${process.env.HTTP_PORT}, description: 'HTTP' }, ], components: { securitySchemes: { actorId: { type: 'apiKey', in: 'header', name: 'x-actor-id', }, actorType: { type: 'apiKey', in: 'header', name: 'x-actor-type', }, }, }, security: [ { ApiKeyAuth: [] }, { ActorTypeAuth: [] }, ], }, }, ) fastify.register(swaggerUi, { routePrefix: '/docs', uiConfig: { docExpansion: 'list', deepLinking: false, }, staticCSP: false, transformSpecification: (swaggerObject, request, reply) => swaggerObject, transformSpecificationClone: true, })

nginx config:
image

Expected Behavior

No response

@mcollina mcollina transferred this issue from fastify/fastify-swagger Sep 26, 2024
@mcollina
Copy link
Member

Transfering to fastify-swagger-ui, because the problem seems to be there.

Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.

@Danko14
Copy link
Author

Danko14 commented Oct 4, 2024

@mcollina
created repo and added steps to reproduce to the issue
https://github.com/Danko14/fastify-swagger

@DavidTanner
Copy link
Contributor

I had the same issue, and found a fix. I assumed the routePrefix needed to start with a /, but if I change the route to docs or swagger then the route resolves correctly.

I tested it with your example repo @Danko14 and was able to get it to work correctly. I had to also change the port in the Dockerfile, but that shouldn't affect the validity of the change.

@DavidTanner
Copy link
Contributor

DavidTanner commented Oct 11, 2024

Relevant PR #164 for Issue #162

@mcollina
Copy link
Member

@DavidTanner Can you send a PR to update the docs for that?

@mcollina mcollina added documentation Improvements or additions to documentation good first issue Good for newcomers labels Oct 12, 2024
@DavidTanner
Copy link
Contributor

I would, but I don't think that is the right way. I'm trying out some other changes

@Danko14
Copy link
Author

Danko14 commented Oct 14, 2024

I assumed the routePrefix needed to start with a /, but if I change the route to docs or swagger then the route resolves correctly.

Genius. Just like I imagined it
Thank you!

@Danko14 Danko14 closed this as completed Oct 14, 2024
@Fdawgs Fdawgs linked a pull request Nov 15, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
3 participants