ad-on-is / adonis-autoswagger

Auto-Generate swagger docs for AdonisJS
MIT License
116 stars 38 forks source link

Scalar API Client Proxy Error #69

Closed maukoese closed 5 months ago

maukoese commented 5 months ago

I love te new Scalar docs, they are very beautiful and well structured.

However, when I try to make any request to test out the API I get the above error.

Screenshot 2024-04-08 at 15 03 16

My config is as below:

import path from 'node:path'
import url from 'node:url'

export default {
  path: path.dirname(url.fileURLToPath(import.meta.url)) + '/../',
  title: 'SBDC API',
  version: '1.0.0',
  tagIndex: 2,
  snakeCase: false,
  ignore: [
    '/swagger',
    '/docs',
    '/api/internal',
    '/admin',
    // '/partner',
    // '/login',
    // '/register',
    '/jobs',
    '/2fa',
    '/logout',
    '/password',
    '/inertia',
    '/ask',
    '/about',
    '/contact',
    '/auth/*',
    '/portfolio',
    '/our-partners',
    '/p/*',
    '/c/*',
  ],
  preferredPutPatch: 'PUT',
  common: {
    parameters: {
      page: 1,
      per: 10
    },
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    },
  },
  persistAuthorization: true,
  showFullPath: false,
}

and the routes

router.get('swagger', async () => {
  return AutoSwagger.default.docs(router.toJSON(), swagger)
})

router.get('docs', async () => {
  // return AutoSwagger.default.ui('/swagger', swagger)
  return AutoSwagger.default.scalar('/swagger')
})
ad-on-is commented 5 months ago

I'm not 100% sure, but looks like scalar calls api.scalar.com which then tries to connect to localhost:3333 (in my case) .. and this obviously wouldn't work, since their server does not know anything about localhost:3333.

I assume, this should work if your app is hosted publicly with an accessible URL like https://myapp.googleapps.com or similar.

maukoese commented 5 months ago

Okay. Let me deploy to production then try.

ad-on-is commented 5 months ago

@maukoese Did it work on production?

maukoese commented 5 months ago

@ad-on-is Yes it does, thank you.

EvandroVV93 commented 5 months ago

@maukoese


import scalarCustomCss from '#config/scalar'

router.get('/docs', async () => {
  return `
  <!doctype html>
  <html>
    <head>
      <title>API</title>
      <meta charset="utf-8" />
      <meta
        name="viewport"
        content="width=device-width, initial-scale=1" />
      <style>
      ${scalarCustomCss}
      </style>
    </head>
    <body>
      <script
        id="api-reference"
        data-url="/swagger"
      <script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
    </body>
  </html>
`
})

this works if you still want to use scalar!