Swagger: It changing protocol from http to https on VPS and show blank page, while URL is on http

Created on 23 Oct 2020  路  4Comments  路  Source: nestjs/swagger

I'm submitting a...


[ ] Regression 
[x ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior


Hello guys, I have an issue on my server (on localhost everything is good) with requests from swagger page to its resources, it call https:// when I am on http://server:5556/docs/ . I see only blank page, without any data.
In Chrome Dev Tools I see Console logs:
GET https://{server}:5556/docs/swagger-ui.css net::ERR_SSL_PROTOCOL_ERROR GET https://{server}:5556/docs/swagger-ui-bundle.js net::ERR_SSL_PROTOCOL_ERROR ....

Looks like it calls https instead of http, but SSL is not configured on my API, and I am not use NGINX or something.
Its very important that problem isnt on localhost, its on my VPS.
There is my configuration (also problems are exists without bearer or addServer):

const options = new DocumentBuilder()
    .setTitle('NestJS Realworld Example App')
    .setDescription('The Realworld API description')
    .setVersion('1.0')
    .setBasePath('api/icw')
    .addServer('http://localhost:5556')
    .addServer(`http://${server}:5556`)
    .addBearerAuth()
    .build()
  const document = SwaggerModule.createDocument(app, options)

What I should do to fix the swagger ui page on http protocol?
I tried to find answers on swagger.io and Nest docs, but I dont know what I need to fix.

Thank you very much

Here is my Chrome DevTools /docs request inspect, why it call to https resources? How to fix that?
袘械蟹 薪邪蟹胁邪薪懈褟

Expected behavior


Going on /docs page should give us scheme, and requests should go on http instead of https protocol.

Environment


Nest version: 7.4.4
"@nestjs/swagger": "^4.6.1",
"swagger-ui-express": "^4.1.4",


For Tooling issues:
- Node version: 12.16.1 (LTS)  
- Platform:  Linux (Docker - node:lts-alpine) 

potential issue question

Most helpful comment

I discovered everything and find the issue, i just needed to remove helmet express plugin:

// app.use(helmet())

Looks like it forces finding resources on https scheme, even if it not configured yet. Thanks @nartc , I think you can close issue.

All 4 comments

@taipoxin I'm pretty sure this is an issue on swagger-ui-express side. There's one similar but it was closed by the issue opener (https://github.com/scottie1984/swagger-ui-express/issues/212). Can you try opening an issue on swagger-ui-express?

@nartc Thank you, I'll look on swagger-ui-express

I discovered everything and find the issue, i just needed to remove helmet express plugin:

// app.use(helmet())

Looks like it forces finding resources on https scheme, even if it not configured yet. Thanks @nartc , I think you can close issue.

Guys no need to remove helmet, just move the swagger above the helmet registration like so:

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

app.use(helmet());
Was this page helpful?
0 / 5 - 0 ratings

Related issues

cdiaz picture cdiaz  路  4Comments

ericzon picture ericzon  路  4Comments

malbertSC picture malbertSC  路  5Comments

ivashog picture ivashog  路  3Comments

KatSick picture KatSick  路  3Comments