fastify-swagger-ui icon indicating copy to clipboard operation
fastify-swagger-ui copied to clipboard

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

Open Danko14 opened this issue 5 months ago • 2 comments

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] 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

Danko14 avatar Sep 24 '24 06:09 Danko14