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

/swagger/json returning 404 if Swagger is used in conjunction with a prefix set in Elysia #183

Open
sludgepudge opened this issue Jan 12, 2025 · 5 comments · May be fixed by #185
Open

/swagger/json returning 404 if Swagger is used in conjunction with a prefix set in Elysia #183

sludgepudge opened this issue Jan 12, 2025 · 5 comments · May be fixed by #185

Comments

@sludgepudge
Copy link

When setting a prefix in Elysia and simultaneously using Swagger, it fails to correctly load /swagger/json.

To reproduce:

new Elysia({ prefix: '/v1' })
	.use(swagger())
	.use(logixlysia()) // logger used to highlight responses on console
	.get('/', () => 'Hello!')
	.listen(3000);

Visit the server in a browser http://localhost:3000/v1/swagger and you'll be presented with the UI theme of Scalar, but no content.

Adding a logger reveals that /v1/swagger gets hit and returns a 200 status, immediately followed by /swagger/json (note the lack of prefix) getting hit with a 404 status.

It seems this has been attempted to be fixed before #16 but has remained an ongoing issue since at least October 2024.

image image
@Mikey-ShenSu
Copy link

If you’re using Next.js, here’s a temporary solution to address the issue:

// src/app/swagger/json/page.tsx
import { redirect } from "next/navigation";

export default function SwaggerPage() {
  redirect("/api/swagger/json");
}

For a pure Elysia JS project (used as an API only), you can apply the same approach by redirecting the endpoint to /api/swagger/json. The concept remains the same.

@TheGU
Copy link

TheGU commented Jan 19, 2025

Thie pr #146 force a path to always start at root instead of relative path, so json file not found when we set a preix in elysia.

@chrisllontop
Copy link
Contributor

@TheGU my apologies for that. I’ll fix that asap. Thanks!

@Euraxluo
Copy link

Is it really that complicated?

@Euraxluo
Copy link

log:GET /sw.js 404 in 63ms

@bhaleraosaurabh bhaleraosaurabh linked a pull request Jan 30, 2025 that will close this issue
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.

5 participants