Forum Discussion
ponelat
Staff
Hi asaddev ,
Typically when we see raw HTML coming back, it's because express is treating that route as "text/plain" or similar. Look to see if req.type() is being called before your call to swaggerUi.serve. Or some other method that would change the "Content-Type" of the response.
You can confirm the Content-Type is bad, by using curl or similar..
curl -i http://localhost:3000/api-docs
#...
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8 <------ Good content-type
#...
Here is a minimal index.js that works...
const swaggerUi = require('swagger-ui-express')
const swaggerDocument = require('./swagger.json')
const express = require('express')
const app = express()
app.use(
'/api-docs',
swaggerUi.serve,
swaggerUi.setup(swaggerDocument)
);
const server = app.listen(3000, () => {
console.log(`Server running at ${server.address().port}`);
});
asaddev
2 years agoNew Contributor
Hey,
Thanks for the reply.
I have checked of what you had given, but even after that the same issue is coming. Kindly checked the attached screenshot below.
Note: I am using ES6 in this.
Related Content
- 2 years ago
Recent Discussions
- 16 days ago
- 19 days ago