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

Issue with index html resources paths when using a complex path as route prefix #180

Open
2 tasks done
jpb06 opened this issue Oct 17, 2024 · 8 comments · May be fixed by #186
Open
2 tasks done

Issue with index html resources paths when using a complex path as route prefix #180

jpb06 opened this issue Oct 17, 2024 · 8 comments · May be fixed by #186

Comments

@jpb06
Copy link

jpb06 commented Oct 17, 2024

Prerequisites

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

Fastify version

5.0.0

Plugin version

5.1.0

Node.js version

20.18

Operating system

macOS

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

15.0.1

Description

It's appears #178 is causing an issue when using a complex path in routePrefix, ie:

await this.instance.register(fastifySwaggerUI, {
  routePrefix: '/api/vi/$docs'
});

The resolved path looks like /api/v1/api/v1/$docs/static in that case.

image

See linked repo for MRE.

Link to code that reproduces the bug

https://github.com/jpb06/fastify-swagger-ui-routeprefix-issue-repro

Expected Behavior

index resources to load properly.

@mcollina
Copy link
Member

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@jpb06
Copy link
Author

jpb06 commented Oct 18, 2024

Hello.

I spent some time yesterday trying to solve the issue while retaining the behavior wanted by @DavidTanner. Sadly I'm needed elsewhere so I won't have much time to investigate further.

@semy
Copy link

semy commented Nov 2, 2024

Please can you fix that? Have the same problem:
Instead of
const prefix = hasTrailingSlash ? .${opts.staticPrefix}:${hasLeadingSlash ? '.' : ''}${opts.prefix}${opts.staticPrefix}``

should be something like that...
const prefix = hasTrailingSlash ? .${opts.staticPrefix}:${hasLeadingSlash ? '' : '/'}${opts.prefix}${opts.staticPrefix}``

Sorry, but the code is pretty ambiguous anyway, I would generally go over it...

@ronielli
Copy link

ronielli commented Nov 4, 2024

How do I solve this problem, I still can't?

@NoisyFlowers
Copy link

I'm seeing the same problem.

Specifying

routePrefix: "/api/v1/help

and hitting localhost:5000/api/v1/help with browser yields a blank page.

Inspecting the network activity, the initial GET on http://localhost:5000/api/v1/help works, but the ensuing resource GETs all receive 404s because their paths look like this

/api/v1/api/v1/help/static/swagger-ui-bundle.js

Interestingly, adding a trailing "/" (e.g. localhost:5000/api/v1/help/) fixes the problem.

@DavidTanner
Copy link
Contributor

Correct me if I'm wrong, but it kind of seems like this is a bad setup of the server. Can someone please post a test example? I'm going to try recreating in the project as well.

My first thought is that the fastify instance is already using that route prefix, and then you are specifying it again in the swagger config. Again, that is my first thought and I could totally be wrong.

DavidTanner added a commit to DavidTanner/fastify-swagger-ui that referenced this issue Nov 6, 2024
@DavidTanner
Copy link
Contributor

I figured out the issue, and will create a PR to fix. I need to add a new parameter to specify a prefix that only affects the index.html file.

DavidTanner added a commit to DavidTanner/fastify-swagger-ui that referenced this issue Nov 6, 2024
@DavidTanner DavidTanner linked a pull request Nov 6, 2024 that will close this issue
4 tasks
@ronielli
Copy link

Good morning, everyone. Do you have an estimated time to approve this pull request?

@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
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants