Prerequisites
Fastify version
5.6.1
Plugin version
5.2.3
Node.js version
22.x
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
26.0.1
Description
Just noticed that the ui is not correctly loading when its behind a reverse proxy.
The plugin is configured as follow:
import fastifySwaggerUi from '@fastify/swagger-ui'
fastify.register(fastifySwaggerUi, { routePrefix: '/swagger' })
When i try to visit the url
https://api.something.io/service/swagger
the index site was returned but contains not the prefix, which leads to 404
<link rel="stylesheet" type="text/css" href="/swagger/static/swagger-ui.css">
<link rel="stylesheet" type="text/css" href="/swagger/static/index.css">
https://api.something.io/service/swagger/ ( with slash at the end )
the page is loading and the urls are:
<link rel="stylesheet" type="text/css" href="./static/swagger-ui.css">
<link rel="stylesheet" type="text/css" href="./static/index.css">
Additional info:
the forward headers are set correct, but looks like the code does not consider them
'x-forwarded-host': 'api.something.io',
'x-forwarded-port': '443',
'x-forwarded-prefix': '/service',
'x-forwarded-proto': 'https'
tried to use indexPrefix with /service which fixed the issue when its behind the proxy, but breaks if you visit directly the service https://service.something.io/swagger
Link to code that reproduces the bug
Expected Behavior
if x-forwarded-prefix is defined, it should be used.
Prerequisites
Fastify version
5.6.1
Plugin version
5.2.3
Node.js version
22.x
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
26.0.1
Description
Just noticed that the ui is not correctly loading when its behind a reverse proxy.
The plugin is configured as follow:
When i try to visit the url
https://api.something.io/service/swaggerthe index site was returned but contains not the prefix, which leads to 404
https://api.something.io/service/swagger/( with slash at the end )the page is loading and the urls are:
Additional info:
the forward headers are set correct, but looks like the code does not consider them
tried to use
indexPrefixwith/servicewhich fixed the issue when its behind the proxy, but breaks if you visit directly the servicehttps://service.something.io/swaggerLink to code that reproduces the bug
Expected Behavior
if
x-forwarded-prefixis defined, it should be used.