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.41k stars 225 forks source link

css file dosent load on production #312

Closed m0x61h0x64i closed 1 year ago

m0x61h0x64i commented 1 year ago

index.js :

const swaggerUi = require('swagger-ui-express')
const swagger = require('./swagger')
app.use('/api-docs', swaggerUi.serve, swagger)

swagger file :

const swaggerJsDoc = require('swagger-jsdoc')
const swaggerUi = require('swagger-ui-express')

swaggerOptions = {
    swaggerDefinition: {
        openapi: '3.0.1',
        info: {
            title: 'APIs',
            version: '2.0.0'
        },
        servers:
        [
            {
                url: 'http://localhost:3000'
            }
        ],
        components: {
            securitySchemes:
            {
                    JWT: 
                {
                    name: 'User Authorization',
                    description: 'Value: Bearer {token}',
                    type: 'apiKey',
                    scheme: 'bearer',
                    in: 'header',
                    bearerFormat: 'JWT'
                }
            }
        }
    },
    apis: ['./routes/*.js']
}

const swaggerDocs = swaggerJsDoc(swaggerOptions)

const options = {
    customCss: '.swagger-ui .topbar { display: none }'
}

module.exports = swaggerUi.setup(swaggerDocs)
scottie1984 commented 1 year ago

Your url is set to localhost. You will need to change the URL based on the environment

m0x61h0x64i commented 1 year ago

Your url is set to localhost. You will need to change the URL based on the environment

i removed the production server. you can consider that the above code has an production url like this :

servers:
        [
            {
                url: 'https://@example.com'
            }
        ]

it dosent work.

m0x61h0x64i commented 1 year ago

Your url is set to localhost. You will need to change the URL based on the environment

could you please test the above code ? it dosent work im 100% sure

gabrielpra1 commented 1 year ago

I'm also facing a similar issue.

I can see that the network request for swagger-ui.css is actually returning the HTML code instead of CSS.

tnwanna commented 1 year ago

Running into the same issue as well

anjitpariyar commented 1 year ago

@m0x31h0x64i did you solve it ? im also facing the similar issue

m0x61h0x64i commented 1 year ago

Hello @anjitpariyar, no bro i still have this problem.

anjitpariyar commented 1 year ago

@m0x31h0x64i I moved to swagger json and used cdn for CSS, its working for me at least like this ` const swaggerDocument = require("./swagger.json"); const swaggeroptions = { customCssUrl: "https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.18.3/swagger-ui.css", };

// connecting to swagger app.use( "/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument, swaggeroptions) ); `