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

Compatibility issue with Vite in AdonisJS v6 - Swagger UI not rendering #155

Open
diogocoutinho opened this issue Mar 3, 2025 · 1 comment

Comments

@diogocoutinho
Copy link

Description:
I encountered an issue where the adonis-autoswagger package stops rendering the Swagger UI after integrating Vite into my AdonisJS v6 project. Before adding Vite, everything was working perfectly, but after installation and configuration, accessing /docs/swagger results in a 404 Not Found error.

Steps to Reproduce

  1. Install AdonisJS v6 and adonis-autoswagger.
  2. Confirm that Swagger UI is accessible via /docs/swagger.
  3. Install and configure Vite following the official AdonisJS documentation.
  4. Try accessing /docs/swagger again.
  5. Observe that the page is no longer accessible, and the API spec files (swagger.json, swagger.yml) seem to be inaccessible.

Expected Behavior

Swagger UI should continue to work even after integrating Vite, without breaking the ability to serve API documentation.

Image

Current Behavior

  • /docs/swagger returns Cannot GET /docs/swagger.
  • Swagger JSON/YAML files are no longer accessible.
  • No clear errors related to adonis-autoswagger appear in the logs.

Workaround Attempts

  1. Manually adding routes to serve swagger.json and swagger.yml did not fully resolve the issue.
  2. Ensuring the vite middleware is loaded after core middlewares in start/kernel.ts.
  3. Adding explicit proxy rules in vite.config.ts:
    server: {
      proxy: {
        '/docs/swagger.json': 'http://localhost:3333',
        '/docs/swagger.yml': 'http://localhost:3333'
      }
    }
    However, Swagger UI still fails to load correctly.

Possible Cause

It seems that after enabling Vite, AdonisJS is no longer serving the swagger.json and swagger.yml files correctly. Vite might be interfering with static file serving, causing adonis-autoswagger to break.

Environment

  • AdonisJS Version: 6.x

  • adonis-autoswagger Version: (latest)

  • Vite Version: (latest)

  • Node.js Version: v22.13.0

  • Operating System: macOS

Request for Help

Could you provide guidance on how to properly configure adonis-autoswagger to work alongside Vite? Any recommendations on middleware configuration or alternative ways to serve Swagger UI would be highly appreciated.

Thanks in advance!

@ad-on-is
Copy link
Owner

ad-on-is commented Mar 4, 2025

Tbh, I haven't used Vite with adonisjs, and I'm not familiar how it intercepts with the routes.

Do any other routes work that return a simple JSON?

Something like GET /test and just return {"hello": "world"} If that doesn't work, then you have to dig through the AdonisJS docs to see what's going on.

No errors from adonis-autoswagger simply means that it isn't even loaded, which is obvious, because of 404

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

No branches or pull requests

2 participants