scottie1984 / swagger-ui-express

Adds middleware to your express app to serve the Swagger UI bound to your Swagger document. This acts as living documentation for your API hosted from within your app.
MIT License
1.4k stars 225 forks source link

totally does not load on production #358

Open m0x61h0x64i opened 10 months ago

m0x61h0x64i commented 10 months ago

Hi, yesterday I could load my swagger docs using its URL, but today when i committed my new changes it no longer loads my swagger docs on production, but on the development everything works fine.

my last commit was on Jul 3, at that moment until new commit which was today i dint have problem because yesterday docs loaded fine

after i pushed my new commit today, swagger does not load on production, i can see some errors in the console :

image

swagger-ui-bundle.js:3 Uncaught SyntaxError: Unexpected token '<' (at swagger-ui-bundle.js:3:1)
swagger-ui-standalone-preset.js:3 Uncaught SyntaxError: Unexpected token '<' (at swagger-ui-standalone-preset.js:3:1)
DevTools failed to load source map: Could not load content for https://*/api-docs/swagger-ui.css.map: Unexpected token '<', "
<!-- HTML "... is not valid JSON
swagger-ui-init.js:58 Uncaught ReferenceError: SwaggerUIBundle is not defined
    at window.onload (swagger-ui-init.js:58:7)

I have tried disabling all routes, cause i have written new routes and docs, but that didnt help.

now this is my localhost : image

and this is my production swagger : image

swagger-jsdoc version : 6.2.8 swagger-ui-express version : 5.0.0 hosting: vercel

my problem wont be my code, i have checked my Jul 3 commit and it is the same code as it is and also i removed the routes to test if it can be loaded or not but it didnt load swagger doc on production.

EDIT: I have gone to my Jul 3 commit which was the working state of the swagger doc, and it works.

I found the bug, the bug here is that the new version of swagger-ui-express is not compatible with swagger-jsdoc version 6.2.8 but with swagger-ui-express version 4.6.3 and swagger-jsdoc version 6.2.8 it works as expected.

rohithSSV commented 10 months ago

Screenshot 2023-09-06 110335_1 Can we enable swagger UI in HTTP also

urvashichhabra commented 9 months ago

Facing same issue as @m0x61h0x64i.

urvashichhabra commented 9 months ago

Fixed this issue with a workaround. Changes made in esbuild.config.js.

const { build } = require('esbuild');
const { copy } = require('esbuild-plugin-copy');

build({
    entryPoints: ['index.ts'],
    outdir: 'build',  // destination folder 
    sourcemap: 'inline',
    platform: 'node',
    bundle: true,
    plugins: [
        copy({
            assets: [
                {
                    from: ['./node_modules/swagger-ui-dist/swagger-ui-bundle.js'],
                    to: 'build/SwaggerUIBundle.js',   // in destination folder
                },
                {
                    from: [
                        './node_modules/swagger-ui-dist/swagger-ui-standalone-preset.js',
                    ],
                    to: 'build/SwaggerUIStandalonePreset.js',  // in destination folder
                },
            ],
        }),
    ],
}).catch(() => process.exit(1)); // Exit with an error code on build failure